lkml.org 
[lkml]   [2004]   [Jan]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: GCC 3.4 Heads-up
Krzysztof Halasa wrote:
> Bill Davidsen <davidsen@tmr.com> writes:
>
>
>>I would probably write
>> ( a ? b : c ) = d;
>>instead, having learned C when some compilers parsed ? wrong without
>>parens. Actually I can't imagine writing that at all, but at least
>>with parens humans can read it easily. Ugly code.
>>
>>Your suggestion is not portable, if b or c are declared "register"
>>there are compilers which will not allow taking the address, and gcc
>>will give you a warning.
>
>
> One can write as well:
>
> if (a)
> b = d;
> else
> c = d;
>
> Might be more readable and it is what the compiler does.

Since that's a matter of taste I can't disagree. The point was that the
original post used
*(a ? &b : &c) = d;
which generates either warnings or errors if b or c is a register
variable, because you are not allowed to take the address of a register.
It seems gcc does it anyway by intuiting what you mean, but it's not
portable in the sense of being error-free code.

It was a nit, I didn't mean to start a controversy, although if "d" is
actually a complex expression it is certainly less typing as I showed
it, and prevents a future maintainer from changing one RHS and not the
other. That's defensive programming.


--
bill davidsen <davidsen@tmr.com>
CTO TMR Associates, Inc
Doing interesting things with small computers since 1979
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:59    [from the cache]
©2003-2011 Jasper Spaans