[Mono-list] LCC and CIL
Michael Poole
poole@troilus.org
12 Mar 2002 17:25:29 -0500
"Dominic Cooney" <dominic@dcooney.com> writes:
> I guess I need to brush up on my C! gcc allows this:
>
> #include <setjmp.h>
>
> jmp_buf env_buf;
>
> int funcA()
> {
> int v = setjmp(env_buf);
> printf("setjmp returned %d\n", v);
> return v;
> }
>
> int main()
> {
> if (!funcA())
> longjmp(env_buf, 1);
> }
>
> gcc's executable works correctly, and I thought the program was legal.
> MSVC++ accepts it and prints "setjmp returned 0, setjmp returned 1" but
> then crashes.
What is "works correctly"? I don't have an ANSI/ISO C spec handy, but
http://www.opengroup.org/onlinepubs/007908799/xsh/longjmp.html (the
longjmp() specification from SuSv2) says that the behavior of
longjmp(env_buf, ...) is undefined if the corresponding
setjmp(env_buf) was called from a function that has returned. This is
the case in the above code.
-- Michael Poole