With the code,
const double rotationStep = 0.001;
const int N = 2*int(M_PI/rotationStep) + 3;
static unsigned int counts[N];
g++ gives the error:
array bound is not an integer constant before »]« token
I am using g++/gcc version 4.6.1
Can anybody tell me why g++ complains about the expression?
As of the ISO C++ standard of 2003, that’s not an integral constant-expression. Quoting section 5.19 of the standard:
You could change this:
to this:
(That’s assuming
M_PIis defined somewhere; it’s not specified in the standard, but it’s a common extension.)The 2011 ISO C++ standard loosens this up a bit. 5.19p3 (quoting the N3337 draft) says:
I think
2*int(M_PI/rotationStep) + 3, and thereforeN, qualifies under the new rules, but it’s likely your compiler doesn’t yet implement them.