Initializer element Error

V

vib

Hi there,

I wish to get some advice on the problem I face in initializing a
table.

Here is the code. I've an array of strings, ptrNameString . I want to
initialize a table, mySoftKeyTable with some contents of the string
from the array. This initialization is not in any function, but rather
outside of any function. However, the compiler complaints, the related
lines( L1, L2, L3, L4) of "Initializer element is not constant". I
guess, it expects a constant but getting a non-constant instead.

Please advise.

Thanks in advance.
vibnwis

char * ptrNameString [5] = { "One", "Two", "Three", "Four", "Five" };

WWM_SOFTKEY_ITEM_DATA mySoftKeyTable[] =
/* L1 */ {{
/*adrStrings[STR_SETUP].textStr[ENGLISH]*/*(ptrNameString),
(void (* ) (void *)) winHelloCreate, UGL_NULL, 0},
/* L2 */ {
/*adrStrings[STR_DIAL].textStr[ENGLISH]*/*(ptrNameString+1), (void (* )

(void *)) winHelloCreateLine2, UGL_NULL, 1 },
/* L3 */ {
/*adrStrings[STR_REDIAL].textStr[ENGLISH]*/*(ptrNameString+2), (void (*
)
(void *)) winHelloCreateLine3, UGL_NULL, 2 },
/* L4 */ {
/*adrStrings[STR_EXIT].textStr[ENGLISH]*/*(ptrNameString+3),
(void (* ) (void *)) winHelloCreateLine4, UGL_NULL, 3 },
{ UGL_NULL, UGL_NULL, UGL_NULL, UGL_NULL} };

Note: winHelloCreateX are functions.
 
J

Jack Klein

Hi there,

I wish to get some advice on the problem I face in initializing a
table.

Here is the code. I've an array of strings, ptrNameString . I want to
initialize a table, mySoftKeyTable with some contents of the string
from the array. This initialization is not in any function, but rather
outside of any function. However, the compiler complaints, the related
lines( L1, L2, L3, L4) of "Initializer element is not constant". I
guess, it expects a constant but getting a non-constant instead.

Please advise.

The first thing that I advise is to rewrite this code, it is
unreadable. Remove the commented out material. I had to paste this
into a syntax coloring editor to begin to get a grip on it, and hope
the coloring is right.
Thanks in advance.
vibnwis

char * ptrNameString [5] = { "One", "Two", "Three", "Four", "Five" };

WWM_SOFTKEY_ITEM_DATA mySoftKeyTable[] =

What in the heck is a "WWM_SOFTKEY_ITEM_DATA"? What are its
components?

/* L1 */ {{
/*adrStrings[STR_SETUP].textStr[ENGLISH]*/*(ptrNameString),
(void (* ) (void *)) winHelloCreate, UGL_NULL, 0},

If my editor colored your code correctly, after replacing comments
with a single white space, the three lines above are:

{{
*(ptrNameString),
(void (* ) (void *)) winHelloCreate, UGL_NULL, 0},

....is that correct?

In that case, I am guessing that the first member of a
"WWM_SOFTKEY_ITEM_DATA" is a char, or at least an integer type?

In any case, it appears that you are trying to initialize this member
of the first "WWM_SOFTKEY_ITEM_DATA" in the array with:

*(prtNameString)

....and you can't do that. Objects at file scope must be initialized
with constant expressions, and the value of an object is not a
constant expression in C.

If you want to initialize the first member to the letter '0', just
write 'O' as an initializer in the source.
 
V

vib

hi Jack

Many thanks for your time and efforts. The comments were actually
added for the reasons to enhance my explanation. They were not there in
my code.

Yeah. I am agree with you. Boss is asking for a easy-understand table (
not initialize it in runtime). I am cracking my head with the
solution. Apparently not working.
Is there any workaround, so that I can initialize the table before
getting into runtime.

Thanks
 
P

pete

vib said:
hi Jack

Many thanks for your time and efforts. The comments were actually
added for the reasons to enhance my explanation. They were not there in
my code.

Yeah. I am agree with you. Boss is asking for a easy-understand table (
not initialize it in runtime). I am cracking my head with the
solution. Apparently not working.
Is there any workaround, so that I can initialize the table before
getting into runtime.

Change the type of the first member of the structure, to char **

/* BEGIN new.c */

#include <stdio.h>

char * ptrNameString [] = { "One", "Two", "Three", "Four", "Five" };

char **pointer = ptrNameString+2;

int main(void)
{
puts(*pointer);
return 0;
}

/* END new.c */
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top