03-19-2013 04:16 PM
Can someone tell me why the compiler complains when I do this:
const int MY_CONST = 100; char *myStr[MY_CONST];
This is being done outside of a function, as I want myStr to be a global variable.
I get an error saying the initializer must be constant. I've tried this with other compilers, and they don't complain. Any ideas?
Thanks.
03-19-2013 06:29 PM - edited 03-19-2013 06:30 PM
In C a variable of type int remains a variable, even if the const keyword prevents it is modifiend during program life. Given this, C does not permit to use it in a array definition since it is not a "constant". As far as I know C++ does permit this declaration.