static const array of const structure

D

Dario de Judicibus

I wish to define in my application a static constant array of static
constand structure. I am not sure which is the right declatarion and
initialization.

For example, if structure is

MYSTRUCT.H
struct MyStruct
{
String name ;
int value ;
}
static const MyStruct * const arrayOfMyStruct ;

is that correct?

const MyStruct arrayOfMyStruct[] =
{
{"George",127},
{"Mary",212}
} ;

DdJ
 
R

Rolf Magnus

Dario said:
I wish to define in my application a static constant array of static
constand structure. I am not sure which is the right declatarion and
initialization.

For example, if structure is

MYSTRUCT.H
struct MyStruct
{
String name ;
int value ;
}
static const MyStruct * const arrayOfMyStruct ;

That's not an array, but a pointer. And since that pointer is const,
you'd have to initialize it immediately. It can't be changed later. But
it doesn't match the below definition, which is not a pointer, but an
array.
If you want to declare your array in the header, you need to add the
size and make it extern. The rest has to look the same as in the
definition:

extern const MyStruct arrayOfMyStruct[2];
is that correct?

const MyStruct arrayOfMyStruct[] =
{
{"George",127},
{"Mary",212}
} ;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top