c++/9881: Incorrect address calculation for static class member

Wolfgang Bangerth bangerth@ticam.utexas.edu
Thu Feb 27 23:09:00 GMT 2003


>    bar v;
>    double *module::b = &(((bar *)(&v))->p); // LINE X
>    //double *module::b = &(((bar *)(&module::storage))->p); // LINE Y
> 
> If you run this with gcc3.3, the output is:
> 
> @awk[5]% a.out
> 0x8049a50 0x8049a48
> 
> Now comment out LINE X, and uncomment LINE Y and run again getting output:
> 
> @awk[6]% a.out
> 0x8049a78 0
> 
> Zero (0) is not an acceptable address.

Well, zero is the value the standard prescribes of initial initialization, 
i.e. before dynamic initializers are run.

> BUT, the only different between these 2
> lines is the chunk of storage for the object. Notice this has nothing to do
> with the constructor. One case works and one doesn't. Is this not compelling?

Well, all the questions you raise boil down to the question: what is an 
address constant expression. Apparently, the compiler chooses to consider 
the initializer in line X to be one, while it doesn't for line Y. I cannot 
answer the question further than what I did in my previous mail, apart 
from the fact that line X has not cast (or, rather: a cast from one type 
to itself), while line Y has a (reinterpret_)cast from type module to 
incompatible type bar.

Just as an aside, independent of the validity of the PR in itself: why are 
you making it so particularly hard for the compiler to decide this? You 
are setting module::b to &module::storage; there is simple syntax to 
achieve this goal than teh one you use, no? :-)

Cheers
  W.

-------------------------------------------------------------------------
Wolfgang Bangerth             email:            bangerth@ticam.utexas.edu
                              www: http://www.ticam.utexas.edu/~bangerth/




More information about the Gcc-bugs mailing list