Why isn't this expression const?
Daniel Keep
daniel.keep.lists at gmail.com
Wed May 9 21:37:41 PDT 2007
Brian Palmer wrote:
> Frits van Bommel Wrote:
>
>> Silverling wrote:
>>> Brian Palmer Wrote:
>>>
>>>> ...
>> I can't get it to compile for ints either...
>
> Sorry, now that I read what I wrote I wasn't clear. I didn't mean changing float to int, I meant doing:
>
> const int a = 5;
> const int b = a*-1;
>
> works as expected.
>
>>> 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.
>
> Yes, thanks.
Look at the error you got: the compiler is converting ROT_FORCE_CCW.y
into *(&ROT_FORCE_CCW + 4), and since pointers can't be used at
compile-time, the evaluation fails.
A workaround might be to store 400_000 in a named constant, and use that
instead.
const ROT_FORCE = 400_000.;
const Vector3 ROT_FORCE_CCW = {0, ROT_FORCE, 0};
const Vector3 ROT_FORCE_CW = {0, -ROT_FORCE, 0};
-- Daniel
--
int getRandomNumber()
{
return 4; // chosen by fair dice roll.
// guaranteed to be random.
}
http://xkcd.com/
v2sw5+8Yhw5ln4+5pr6OFPma8u6+7Lw4Tm6+7l6+7D
i28a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP http://hackerkey.com/
More information about the Digitalmars-d-learn
mailing list