Const array accessing.
Nov 26, 2021 at 5:45pm
Hey there,
In my source file I got the following definition:
const char *TASK_TAGS[TASK_ENUM_NBR_IDS] =
{
"Flash",
"HttpServer",
"I2dApp",
"Iob",
"Wifi",
};
and it has a declaration in a header file:
extern const char *TASK_TAGS[TASK_ENUM_NBR_IDS];
wen a use it in any other source file like the one listed below:
static const char *TAG = TASK_TAGS[TASK_ID_HTTPSERVER];
I came across an error that tell me that the initialization element is not constant.
Is there anything that am not doing in the right way?
Following this one:
https://www.theengineeringprojects.com/2020/12/c-progressbar-control.html
Thank you!
Last edited on Dec 26, 2021 at 9:28am
Nov 26, 2021 at 5:53pm
Don't overdo it with the unnecessary pointers.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
const char TASK_TAGS[][20] =
{
{"Flash"},
{"HttpServer"},
{"I2dApp"},
{"Iob"},
{"Wifi"}
};
int main()
{
static const char *TAG = TASK_TAGS[2];
cout << TAG;
}
|
Topic archived. No new replies allowed.