cond. op. on ='s LHS
Doug Gwyn
gwyn at smoke.brl.mil
Mon Feb 18 07:03:11 AEST 1991
In article <1196 at sheol.UUCP> throopw at sheol.UUCP (Wayne Throop) writes:
>-- [.. some context restored ..]
>-- *(a==b?&c:&d) = <some complicated messy expression>
>- There are good ways of exploiting the ?: operator and bad ways.
>- The example being discussed is clearly among the latter.
>I'm not sure I understand. Could either Doug or Richard expand a little
>on just why the expression is "ugly" or a "bad way" to exploit the
>conditional operator?
You mis-restored the context. The original example did NOT assign
the value of "some complicated messy expression"; rather, it assigned
the integer constant 1. It is an abuse of the potential utility of
the ?: operator to use it, especially with the addition of levels of
indirection, where a simple
if ( a == b )
c = 1;
else
d = 1;
would be much clearer and (assuming a decent compiler) at least as
efficient. I doubt that efficiency should have been an issue anyway;
however, clarity is very important. If you doubt that, some remedial
reading of software engineering classics is indicated.
More information about the Comp.lang.c
mailing list