setjmp, longjmp

M

Mantorok Redgormor

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.
 
D

Derk Gwen

(e-mail address removed) (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.
 
I

Ian Woods

(e-mail address removed) (Mantorok Redgormor) wrote in

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.

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top