Re: [GD-General] not sure where to post this question... bit C++ implementation specific....
Brought to you by:
vexxed72
From: brian s. <pud...@po...> - 2004-07-07 18:03:33
|
AFAIK const floats (and const doubles) are treated differently because any compile-time arithmetic you do with them might not give the same results as runtime arithmetic. The results you get depend on what state you've buggered the FPU into (on both the compiling machine and the target machine). So VC will be cautious and defer any division of const floats until runtime, meaning that you can't use it in an array declaration. --brian Noel Llopis wrote: >On Wednesday 07 July 2004 05:23 am, Richard Fabian wrote: > > >>i seem to be able to safely issue declarations for int initialised >>arrays... >> >>e.g. >> >> const int ropeLength = 12.5f; >> const int knotSpace = 3.3f; >> int array[ (int)( ropeLength / knotSpace ) ]; >> >>is perfectly valid. >> >>it looks like it is quite literally the "const float"s that are at >>fault. >> >> > >If I recall correctly, const floats were treated very differently from const >ints in VC++. Const floats even generated their own bit of code to be >executed when they were initialized, whereas const ints became true consts, >so it doesn't surprise me that they can't be used as part of the array size. > >As some other people pointed out earlier, any reason not to use an >std::vector<> or do dynamic allocation? > >If you don't like having to delete the memory, you can always use >boost::scoped_array: >boost::scoped_array<int> array (new[ (int)( ropeLength / knotSpace ) ]); > > > > |