Legal uses of setjmp and GCC
Posted
by
Chris Lutz
on Stack Overflow
See other posts from Stack Overflow
or by Chris Lutz
Published on 2011-01-07T01:51:59Z
Indexed on
2011/01/07
1:53 UTC
Read the original article
Hit count: 472
Using GCC (4.0 for me), is this legal:
if(__builtin_expect(setjmp(buf) != 0, 1))
{
// handle error
}
else
{
// do action
}
I found a discussion saying it caused a problem for GCC back in 2003, but I would imagine that they would have fixed it by now. The C standard says that it's illegal to use setjmp
unless it's one of four conditions, the relevant one being this:
- one operand of a relational or equality operator with the other operand an integer constant expression, with the resulting expression being the entire controlling expression of a selection or iteration statement;
But if this is a GCC extension, can I guarantee that it will work under for GCC, since it's already nonstandard functionality? I tested it and it seemed to work, though I don't know how much testing I'd have to do to actually break it. (I'm hiding the call to __builtin_expect
behind a macro, which is defined as a no-op for non-GCC, so it would be perfectly legal for other compilers.)
© Stack Overflow or respective owner