accessing const array

Hi all -

I have this defined in a source file:

const char *TASK_TAGS[TASK_ENUM_NBR_IDS] =
{
"Flash",
"HttpServer",
"I2dApp",
"Iob",
"Wifi",
};

and declared in a header file:

extern const char *TASK_TAGS[TASK_ENUM_NBR_IDS];

When I try to use it in another source file (like this):

static const char *TAG = TASK_TAGS[TASK_ID_HTTPSERVER];

I get an error: initializer element is not constant.

What am I doing wrong here? Thanks...
can't reproduce, provide a testcase
(don't narrate your code, just show it)
no need for pointers, simpler to say:

const char blah[5][20]=
{"Flash",
"HttpServer",
"I2dApp",
"Iob",
"Wifi"};

and to use it elsewhere just extern it like anything else. I prefer to make a little function that exposes it rather than extern it, but that is your call.
Header:
1
2
3
4
#include <cstddef>

extern const char* const TASK_TAGS[] ;
extern const std::size_t TASK_ENUM_NBR_IDS ;


Source:
1
2
3
4
5
6
7
8
9
10
11
12
// #include header file

const char* const TASK_TAGS[] =
{
    "Flash",
    "HttpServer",
    "I2dApp",
    "Iob",
    "Wifi",
};

const std::size_t TASK_ENUM_NBR_IDS = sizeof(TASK_TAGS) / sizeof( TASK_TAGS[0] )


Usage:
for( std::size_t i = 0 ; i < TASK_ENUM_NBR_IDS ; ++i ) { /* access TASK_TAGS[i] */ }

Topic archived. No new replies allowed.