Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   setjmp, longjmp (http://www.velocityreviews.com/forums/t316170-setjmp-longjmp.html)

Mantorok Redgormor 11-12-2003 02:57 PM

setjmp, longjmp
 
is there a portable way of implementing exception handling with setjmp, longjmp?

restoring the state of a program and such really seems like I am asking
for undefined behavior.

--
nethlek

Derk Gwen 11-12-2003 03:47 PM

Re: setjmp, longjmp
 
nethlek@tokyo.com (Mantorok Redgormor) wrote:
# is there a portable way of implementing exception handling with setjmp, longjmp?
#
# restoring the state of a program and such really seems like I am asking
# for undefined behavior.

It's the only standard way to exit a nest of called functions to a
particular point in a calling ancestor. You should not expect to restore
local or global variables--if you need that behaviour, store the originals
elsewhere and copy back at the setjmp. You should not expect not to
restore non-volatile variables--if you need that, declare them volatile.

--
Derk Gwen http://derkgwen.250free.com/html/index.html
Haven't you ever heard the customer is always right?

Ian Woods 11-12-2003 04:59 PM

Re: setjmp, longjmp
 
nethlek@tokyo.com (Mantorok Redgormor) wrote in
news:41ec7ac0.0311120657.75f3081b@posting.google.c om:

> is there a portable way of implementing exception handling with
> setjmp, longjmp?
>
> restoring the state of a program and such really seems like I am
> asking for undefined behavior.
>
> --
> nethlek


The only state of the program which is not preserved by longjmping are
automatic variables IIRC. I wrote a toy exception handling 'thing' a long
time ago in here which exploited that fact. You had to specifically
preserve the automatic variables you wanted to keep (and you could keep
them at stages in the 'try' block), but it was all very much a hack.

I'll try and have a dig around and see if I still have it. If not, I might
just rewrite it for laughs.

Ian Woods


All times are GMT. The time now is 02:10 PM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57