LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

compiler error

When I try to compile following code

static int a=1;
static int b=2;
static int c[]={a,b};
...

,I get a compiler error : "Initializer must be constant." at the line with
the assignment of c[]. Even if I declare a and b as const, the message happens.
The same code can be comiled with other ansi compilers without any problems.
Is there known ansi incompatibility at this topic ?
Thanks,
Manfred
0 Kudos
Message 1 of 2
(2,722 Views)
Manfred,

You say ansi compilers, do you mean just ansi C? You cannot initialize an array with non constants in C. You can do the above with C++. What other compilers are you using? Do you have these declarations in a C source or C++ file? Even with const keyword, it is still not allowed in C.
If you are using C, why not just
#define const_a 1
#define const_b 2
static int c[] = {const_a, const_b};
0 Kudos
Message 2 of 2
(2,722 Views)