Why isn't this expression const?
Frits van Bommel
fvbommel at REMwOVExCAPSs.nl
Wed May 9 15:37:50 PDT 2007
Silverling wrote:
> 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)
I can't get it to compile for ints either...
> Try
> const Vector3 ROT_FORCE_CCW = [0, 400_000, 0];
> const Vector3 ROT_FORCE_CW = [0, ROT_FORCE_CCW.y*-1, 0];
>
> That's how you init an array. I assume that Vector3 is an alias for float[3].
It's not an array. Look at the first line of his code: it's a struct.
More information about the Digitalmars-d-learn
mailing list