Compiling GCC With a C++ Compiler (g++)
Kai Henningsen
kaih@khms.westfalen.de
Fri Oct 15 12:48:00 GMT 2004
schwab@suse.de (Andreas Schwab) wrote on 14.10.04 in <jeis9dqn79.fsf@sykes.suse.de>:
> Gabriel Dos Reis <gdr@cs.tamu.edu> writes:
>
> > If you're making the assumption that nonmodifiability necessarily
> > implies that the whole thing is const-qualified, then you're wrong and
> > I'm not surprised you're not satisfied with what the standard says.
>
> You mean that the following (which does not contain any casts) is invoking
> undefined behaviour?
>
> struct A { int a; const int b; } X;
>
> void f (int *x) { *x = 1; }
>
> int main (void) { f (&X.a); return 0; }
Try this instead, which doesn't even use pointers:
struct A { int a; const int b; };
struct A a1;
struct A a2 = { 1, 2 };
...
a1.a = a2.a; // legal
a1.b = a2.b; // illegal
a1 = a2; // illegal
MfG Kai
More information about the Gcc
mailing list