I need some help to find how to resolve this error.
typedef struct {
const char *iName;
const char *iComment;
} T_Entry;
const T_Entry Menu_PowerSupply = { "PWRS", "Power supply"};
static const T_Entry G_Commands[] = {
{ "MEM", "Memory"},
{Menu_PowerSupply.iName,Menu_PowerSupply.iComment},
{ "SYS", "System"}
};
I got the error : expression must have a constant value How can I solve this ?
For me at link time is known and at a fixed address with a fixed value : Am I wrong
My purpose is to put the following code into a library
const T_Entry Menu_PowerSupply = { "PWRS", "Power supply"};
The following not work either
static const T_Entry G_Commands[] = {
{ "MEM", "Memory"},
Menu_PowerSupply,
{ "SYS", "System"}
};
If someone could help me to understand this non const values ...
The error is because the initializer for global variables must be constant expression, but even though Menu_PowerSupply
is defined as const
, it's not a constant expression.
This is similar to:
const int n = 42;
int arr[n];
doesn't compile in C89 because n
is not a constant expression. (it does compile in C99 only because C99 supports VLA)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With