This question already has an answer here:
Typically the '?' operator is used in the following form:
A ? B : C
However in cases where B = A I have seen the following abbreviation
A ? : C
This surprisingly works. Is it better to leave the second parameter in (style wise), or is their a chance certain compilers won't be able to handle this?
i did a little research in the web, acording to wikipedia, this behavior is supported by a GNU extension of C. http://en.wikipedia.org/wiki/%3F:#C
So it is very probable that other compilers consider this illegal. By the way, this operator is called ternary conditional so you can browse about it.
EDIT:
I checked in gcc and apple llvm and it works fine.
It is better to leave the second parameter in. If B ever changes, you may not remember to modify the statement above. Further, other people may have a difficult time reading your code and improving upon it if you leave B out of the statement.
Its a gcc's extension
Conditionals with Omitted Operands
x ? : y
is equivalent tox ? x : y
I fill in a bit.
The standard uses the term conditional operator.
A conditional expression does not yield an lvalue. Also; Wikipedia; Conditional
Note: I.e.: C++ has:
logical-OR-expression ? expression : assignment-expression
Foot food:
* Type qualifiers in C
So: Not wise to use.
It is not permitted by the language C (as far as I know), but compilers such as gcc have the shortcut a?:c as an extension.
a?:c
means the same asa?a:c
.Unless I'm badly mistake, you're using a compiler extension (at a guess, gcc). I'm pretty sure the standard does not allow you to omit the second operand to the ternary operator.