cond. op. on ='s LHS
Dan Bernstein
brnstnd at kramden.acf.nyu.edu
Tue Feb 19 01:26:02 AEST 1991
In article <331 at smds.UUCP> rh at smds.UUCP (Richard Harter) writes:
> Let's run down the line on this. First of all the trick of using
> *(cond?&var1:&var2) is not technically legal since the result of the
> ?: is not an lvalue.
Say what? It doesn't matter whether foobiebletch is an lvalue as long as
nobody tries to assign a value to it. Here foobiebletch is a (non-const)
pointer type, so *foobiebletch is an lvalue, and *foobiebletch = x is
fine.
> Secondly the syntax of the condition is, in its own right, ugly.
Yes. I'd write either
{
register glorp *addr;
if (cond) addr = &var1;
else addr = &var2;
*addr = expr;
}
or
{
register glorp temp;
temp = expr;
if (cond) var1 = temp;
else var2 = temp;
}
if any of the expressions involved were particularly complex. How else
would the machine do the job anyway?
> There really is a need for
> conditional expressions.
This can be argued. ?: is almost purely syntactic; I don't know any
machine that will optimize a ?: expression better than an equivalent
if-then. Its syntactic benefits are minimal at best.
---Dan
More information about the Comp.lang.c
mailing list