I used to do the following to declare and initialize an array of string in C:
char *myTable[] = {
"ABC", "Y", "*", "*",
"WXYZ", "Y", "*", "*",
"MNO", "Y", "*", "*",
NULL, NULL,NULL, NULL
};
The NULL’s are for internal use.
Since I moved to gcc 4.4.6, I get a warning:
abc.cpp:74: warning: deprecated conversion from string constant to ‘char*’
What is the correct way of initializing my array ?
It’s because you’re trying to drop off the constness of these string literals and compiler is considerate enough to warn you about it since trying to modify the memory where these constant string literals are stored leads to undefined behaviour [1]
Declare your array as
const char *myTable[][1]: C99 Standard: 6.7.8 Initialization §32: