Not only is it not documented in the reference guide but it's syntax/use
is counter-intuitive:
http://www.eskimo.com/~scs/cclass/int/sx4eb.html
One would expect false to be represent by 0 and true to be represented by
1
Close enough. A non-zero value is, when evaluated as a condition, taken as
a "TRUE" value, while a zero value is, when evaluated as a condition, taken
as a "FALSE" value.
Your expectations are close enough.
Therefore
A ? B : C
The logical order would be:
A ? 0 : 1
I don't see how you got that. The trinary operator, by definition (and by
analogy to the "if" statement) puts the "true" actions ahead of the "false"
actions.
Either your example is irrelevant (the "true" and "false" actions, after
all, are arbitrary as far as the language is concerned, and only
have "meaning" in the context of the logic in which the trinary operator is
used. In other words, if it is your intent as a programmer to present an
rvalue of 0 when a certain condition is true, and 1 when it is not, then
the above example is correct, otherwise, it is not), or your example is
contrary to the language.
You seem to be saying that (in pseudocode)
IF condition is TRUE
THEN
result is FALSE
OTHERWISE
result is TRUE
FI
is the "logical order" of things, or perhaps that (again in pseudocode)
IF condition is FALSE
THEN
result is FALSE
OTHERWISE
result is TRUE
FI
is the logical order. But, the trinary operator neither orders the false
condition first nor does it evaluate the falseness of the condition.
But instead it's
A ? 1 : 0
If you mean something like
B = A ? 1 : 0;
is like
B = (A != 0)
then, you are correct.
One could argue that this resembles the if-else statement, though the
if-else statement is usually on seperate lines while the question mark is
represented to be on a single line and therefore a completely different
language element thus special treatment is warranted.
Nonsense!!
B = A ? /* test truthfulness of A */
1 : /* A is TRUE - result is 1 */
0 ; /* A not TRUE - result is 0 */
See? Three lines. Just the same as
if (A)
B = 1;
else B = 0;
I find
A ? 0 : 1 more logical in this reguard when seeing it on a single line.
/You/ may find the contra-expression "more logical", but most others don't.
Your failings are none of our business. Why do you feel the need to admit
them to us?
--
Lew Pitcher
Master Codewright & JOAT-in-training | Registered Linux User #112576
http://pitcher.digitalfreehold.ca/ | GPG public key available by request
---------- Slackware - Because I know what I'm doing. ------