lkml.org 
[lkml]   [2004]   [Jan]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: GCC 3.4 Heads-up
From
Date
>>>>> 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/

\
 
 \ /
  Last update: 2005-03-22 13:59    [W:0.112 / U:0.108 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site