franka at mmintl.UUCP franka at mmintl.UUCP
Fri Aug 8 01:13:56 AEST 1986

[Not food]

It seems clear that according to the ANSI draft, e1?e2:e3 is legal when e2
and e3 are both void.  The next question is, should it be?

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, depending
on the value of e1.  This is a very reasonable interpretation; but if it
were correct, there would be one other important consequence which is not in
fact legal.  This is that when e2 and e3 are lvalues, the compound
expression should also be an lvalue.  In particular, one could write

e1?e2:e3 = e4;

which would mean the same thing as

if (e1) then e2 = e4; else e3 = e4;

(This would be permitted only if e2 and e3 had exactly the same type, of
course; one could not do this if e2 was a short and e3 a long.)

This seems to me like a reasonable extension to the language.  But I believe
it should be one or the other -- the draft falls uncomfortably in the middle.

Frank Adams                           ihnp4!philabs!pwa-b!mmintl!franka
Multimate International    52 Oakland Ave North    E. Hartford, CT 06108

More information about the Comp.lang.c mailing list