Why isn't this expression const?

Don Clugston dac at nospam.com.au
Wed May 9 23:44:29 PDT 2007


Brian Palmer wrote:
> This code won't compile:
> 
>  struct Vector3 { float x,y,z; }
>  const Vector3 ROT_FORCE_CCW = {0, 400_000, 0};
>  const Vector3 ROT_FORCE_CW  = {0, ROT_FORCE_CCW.y*-1, 0};
> 
> That last line gives me the error:
> 
>  Error: non-constant expression *((& ROT_FORCE_CCW+4)) * -1.0e+0F
> 
> Strangely, I can do the equivalent three lines with basic types like ints just fine, but I can't get this struct initialization to work. Am I doing something wrong, or is it just lack of compiler smarts? I'm using (gdc 0.23, using dmd 1.007)

It's just lack of compiler smarts. Originally, hardly any constant 
folding worked.


More information about the Digitalmars-d-learn mailing list