Messages in this thread | | | Subject | Re: GCC 3.4 Heads-up | From | David Mosberger-Tang <> | Date | 06 Jan 2004 13:06:19 -0800 |
| |
>>>>> On Fri, 26 Dec 2003 05:50:07 +0100, Linus Torvalds <torvalds@osdl.org> said: Linus> The cast/conditional expression as lvalue are _particularly_ Linus> ugly extensions, since there is absolutely zero point to Linus> them.
I'd love to agree with that...
Linus> They are very much against what C is all about, and writing Linus> something like this:
Linus> a ? b : c = d;
Linus> is something that only a high-level language person could Linus> have come up with. The _real_ way to do this in C is to just Linus> do
Linus> *(a ? &b : &c) = d;
Linus> which is portable C, does the same thing, and has no strange Linus> semantics.
This works provided you can take the address of the lvalue, which ain't true for bitfields. Example:
#define bit_field(var, bit, width) \ (((struct { long : bit; long _f : width; } *) &(var))->_f)
long l;
bit_field(l, 0, 4) = 13; bit_field(l, 8, 12) = 42;
I wish I was making this up, but I know of at least one legacy app where disabling GCC's ability to treat statement-expressions as l-values will cause a major headache.
I'd love to know a way of doing this in ANSI C99 without requiring changes to to uses of this kind of (atrocious) macro...
--david
-- David Mosberger; 35706 Runckel Lane; Fremont, CA 94536; David.Mosberger@acm.org - 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/
| |