In the 3.0.4 Linux kernel, mm/filemap.c has this line of code:
retval = retval ?: desc.error;
I’ve tried compiling a similar minimal test case with gcc -Wall and don’t get any warnings; the behavior seems identical to:
retval = retval ? retval : desc.error;
Looking at the C99 standard, I can’t figure out what formally describes this behavior. Why is this OK?
As several others have said, this is a GCC extension, not part of any standard. You’ll get a warning for it if you use the
-pedanticswitch.The point of this extension is not really visible in this case, but imagine if instead it was
With the extension,
foo()is called only once. Without it, you have to introduce a temporary variable to avoid callingfoo()twice.