A question about the tertiary (? : ) operator

Steve Hosgood iiitsh at cybaswan.UUCP
Sat Aug 19 00:54:49 AEST 1989


I never noticed until last night that the conditional operator:

<condition>? <val1>: <val2>

..is not a valid lvalue, even if both <val1> and <val2> are lvalues!
I wanted to say:

(flag > 0? foo: bar) = <complex expression>;

..which didn't work, needless to say. I had to employ a temporary variable
and an 'if' statement in the end :-(.

Is there a good reason for this behaviour?
Thanks in advance
Steve

-----------------------------------------------+------------------------------
Steve Hosgood BSc,                             | Phone (+44) 792 295213
Image Processing and Systems Engineer,         | Fax   (+44) 792 295532
Institute for Industrial Information Techology,| Telex 48149
Innovation Centre, University of Wales,        | JANET: iiitsh at uk.ac.swan.pyr
Swansea SA2 8PP                                | UUCP: ..!ukc!cybaswan!iiitsh
-----------------------------------------------+------------------------------
            My views are not necessarily those of my employers!
           Please note the change in my username as of 1 Aug '89



More information about the Comp.std.c mailing list