? : operator in lvalue

Ephraim Vishniac vishniac at wanginst.UUCP
Thu Apr 18 04:37:51 AEST 1985


> Is it considered kosher to use the ``? :'' operator
> in computing an lvalue, as in
> 
> 	int a, b, c;
> 
> 	*(a ? &b : &c) = 47;
> 
> This is certainly legal C, but I never recall
> seeing it used in any code I have looked at.

Legality may not be enough: some C compilers will choke on it anyway.
I recently discovered that the Mark Williams C compiler (for 8086/8088)
refuses to accept:

	int a[3], b;

	a[ b ? 1 : 2] = 47;

It complains that the stuff on the left of the assignment is not an lvalue.

-- 
Ephraim Vishniac
  [apollo, bbncca, cadmus, decvax, harvard, linus, masscomp]!wanginst!vishniac
  vishniac%Wang-Inst at Csnet-Relay



More information about the Comp.lang.c mailing list