l i n u x - u s e r s - g r o u p - o f - d a v i s
Next Meeting:
July 7: Social gathering
Next Installfest:
Latest News:
Jun. 14: June LUGOD meeting cancelled
Page last updated:
2006 Dec 07 22:45

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] For "C" gurus
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox-tech] For "C" gurus

Jeff Newmiller wrote:
Richard Harke wrote:
But suppose this is changed to the following:

asub(jmp_buf env)
.....do something
    longjmp(env, 1);

my_wrapper(jmp_buf env)
    int x;

    if (x = setjmp(env)) {
         return x;
     } else {
            return 0;
    jmp_buf env;
some code
     if (my_wrapper(env);) {
/* returned from longjmp */
        clean up
    } else {
/*just returned from setjmp */
        may not return

Notice that because we returned from my_wrapper before
calling asub, the local variables for asub have been
removed from the stack. Thus they cannot be restored
by the longjmp. It seems to me this usage should
be explicitly rejected. Can any one point me to an
authoratative reference that says this?
I don't have the latest standard, but this is covered in ANSI X3.159-1989
Section lines 7-10:

The longjmp function restores the environment saved by the most recent
invocation of the setjmp macro in the same invocation of the program, with
the corresponding jmp_buf argument. If there has been no such invocation,
or if the function containing the invocation of the setjmp macro has
terminated execution in the interim, the behavior is undefined.

Wikipedia has a good article on the subject that should scare you away from using my_wrapper:

vox-tech mailing list

LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
Sunset Systems
Who graciously hosts our website & mailing lists!