GCC 3.4 Heads-up
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · Linus Torvalds
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; [email protected]
Quoted 2 lines · David Mosberger-Tang
This works provided you can take the address of the lvalue, which ain't true for bitfields.
Indeed. Which means that the compiler almost certainly would have done the wrong thing in certain cases with the conditional lvalue extension.
There were real, hard to fix bugs here. Rather than sweat too much about what the "right" semantics are supposed to be, and how to get them all "correct", we just removed the ill-thought extension.
Quoted 2 lines
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...
In ANSI C you've no alternative except memcpy, since you can't cast the pointer and reference the object via some other type (assuming neither type is char, yadda yadda).
r~
Quoted 4 lines · Richard Henderson
In ANSI C you've no alternative except memcpy, since you can't cast the pointer and reference the object via some other type (assuming neither type is char, yadda yadda).
Sure you have. You can _always_ change
(a ? b : c) = d;
to
tmp = d; a ? (b = tmp) : (c = tmp);
which is not pretty, but with some macro abuse it won't be horrible. In fact, once you do that, you might as well just do a real "if" statement.
Especially if you're going to continue to use (less odious) gcc-specific stuff you can probably automate it fairly well with a replacement that uses "typeof" and expresstion statements to do that "tmp" variable properly.
Ie it might be _slightly_ more complex than running a "sed" script over the sources, but it shouldn't be that much worse.
Linus
Quoted 4 lines · Linus Torvalds
Quoted 3 lines
In ANSI C you've no alternative except memcpy, since you can't cast the pointer and reference the object via some other type (assuming neither type is char, yadda yadda).
Quoted 8 lines
Sure you have. You can _always_ change
(a ? b : c) = d;to
tmp = d; a ? (b = tmp) : (c = tmp);
No, I meant his bitfield macro at all. You can't just go and construct a bit field at random and dereference it.
r~