|
From: | Alf P. Steinbach |
Subject: | Re: How to exit out of a function ? what is try-catch-throw in terms of Program Counter |
Date: | Mon, 05 Nov 2007 06:59:50 +0100 |
User-agent: | Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8) Gecko/20051201 Thunderbird/1.5 Mnenhy/0.7.3.0 |
* Alf P. Steinbach:
* David Thompson:On Sun, 21 Oct 2007 00:55:53 +0200, "Alf P. Steinbach" <alfps@start.no> wrote:* gnuist006@gmail.com:The closest equivalent in C would be a 'longjmp'. However, a C++ exception is more limited, in that it will only jump up the call chain,NOTE: I am really afraid of try-catch-throw. I have never been able to understand it since it does not exist in C and I cant really visualize the construct in terms of C. <snip>C longjmp/setjmp also is only guaranteed to work up the stack; the fact that _some_ implementations can work cross-stack and in particular cross-thread is not standard nor portable.So?But also, what on Earth do you mean by a cross-thread longjmp? I implemented coroutines in terms of longjmp at the time that was popular, so the concepts involved are not unfamiliar to me. Yet I fail to envision what you could be talking about, especially as "fact". I think perhaps you're talking about restoring the full context (registers etc) of a moment in a thread's execution?and it's more powerful, in that it will destroy local objects as it does so. Also, if you use 'longjmp' in C++ you're practically doomed (unless you use it to jump between co-routines with their own stacks), because 'longjmp' doesn't destroy local objects.Actually it's Undefined Behavior; a good quality C++ implementation CAN coordinate longjmp, and also pthreads cancellation, with exceptions to destruct locals cleanly -- but it's not required.I don't know about ptheads cancellation, but other than that you're right. Visual C++ coordinates longjmp with C++ stack unwinding. g++, on the other hand, does not.
Sorry, I didn't see the weasel-word "actually", which indicates a contradiction.
When I wrote that you're right, that just meant that you supplied some extra info that wasn't incorrect.
Cheers, - Alf -- A: Because it messes up the order in which people normally read text. Q: Why is it such a bad thing? A: Top-posting. Q: What is the most annoying thing on usenet and in e-mail?
[Prev in Thread] | Current Thread | [Next in Thread] |