I didn't think this was possible but apparently in Objective C it is allowed:
int a = b ?: c;
So you see what they're doing here, they're leaving out the second part of the ternary expression, such that if b is nonzero, b is used as the second part.
It's clever but as far as I know this is against K&R C, and probably ANSI C.
If not, I've been missing out of a terribly clever syntax trick for years...alas!
Update: It is gcc.
From http://en.wikipedia.org/wiki/%3F%3A
This is a GNU C extension. Check you compiler settings (look for C flavor). Not sure if it's part of Clang, the only information I could get is in this page:
So no, it's not allowed. What gcc emits in this case does this:
So the undefined behaviour is doing what you say in your question, even though you don't want to rely on that.
This behaviour is defined for both
gcc
andclang
. If you're building Mac OS X or iOS code, there's no reason not to use it.I would not use it in portable code, though, without carefully considering it.