Re: GCC 3.4 Heads-up

From: Bill Davidsen
Date: Sun Jan 04 2004 - 00:49:04 EST


Krzysztof Halasa wrote:
Bill Davidsen <davidsen@xxxxxxx> 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@xxxxxxx>
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@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/