Orphaned Response

karl at haddock karl at haddock
Sat Aug 16 06:44:00 AEST 1986

mmintl!franka (Frank Adams) writes:
[re the expression e1?e2:e3 where e2 and e3 are void]
>It seems to me that there are two different paradigms for how to interpret
>the ?: operator here.  One is as an ordinary operator, which returns one of
>the values of e2 or e3, depending on the value of e1.  Under this
>interpretation, it does not seem to me appropriate to permit e2 and e3 void,
>since in that case they have no values.
>The other paradigm is that e1?e2:e3 is precisely one of e2 or e3 ...  This
>is a very reasonable interpretation; but [then it should preserve lvalues].
>In particular, one could write "e1?e2:e3 = e4;".

I see your point.  I think both voids and lvalues should be allowed, though
the argument for the latter is less obvious.  I've had a few occasions where
I wanted to use a conditional lvalue, and had to settle for an if-else and a
temporary variable (for e4).  "*(e1?&e2:&e3) = e4;" doesn't work if one of
e2 or e3 is a register or a bit-field, and it looks uglier.  (Also, it tends
to compile into "temp = e1 ? &e2 : &e3; *temp = e4;" rather than "temp = e4;
e1 ? e2 = temp : e3 = temp;", at least on the machines I've tested.)

Karl W. Z. Heuer (ihnp4!ima!haddock!karl), The Walking Lint

More information about the Comp.lang.c mailing list