I have the following:
The above compiled fine, however, if I replace the instance params' unit to the following:
the above was compiled with error:
error C2099: initializer is not a constant
What is the proper way to pass constant char pointer to a constant in this case?
Code:
float var_1, var_2;
const char* const UNIT1 = "kPa";
const char* const UNIT2 = "ft";
struct PARAMETER
{
float* value;
int par_type;
int max_index;
float init;
float min;
float max;
float step;
char* unit;
};
const struct PARAMETER params[] =
{
{
&var_1, //*value
0, //type
0, //max_index
0, //init
0, //min
10, //max
1, //step
"kPa" //unit
},
{
&var_2, //*value
0, //type
0, //max_index
0, //init
0, //min
10, //max
1, //step
"ft" //unit
}
};
Code:
const struct PARAMETER params[] =
{
{
&var_1, //*value
0, //type
0, //max_index
0, //init
0, //min
10, //max
1, //step
UNIT1 //unit
},
{
&var_2, //*value
0, //type
0, //max_index
0, //init
0, //min
10, //max
1, //step
UNIT2 //unit
}
};
error C2099: initializer is not a constant
What is the proper way to pass constant char pointer to a constant in this case?
Comment