LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

const not allowed in global variable definitions?

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.

0 Kudos
Message 1 of 2
(2,646 Views)

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.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 2
(2,639 Views)