I have the following code:
char *array1[3] =
{
"hello",
"world",
"there."
};
struct locator_t
{
char **t;
int len;
} locator[2] =
{
{
array1,
10
}
};
It compiles OK with "gcc -Wall -ansi -pedantic". But with another toolchain (Rowley), it complains about
warning: initialization from incompatible pointer type
on the line where char **t is. Is this indeed illegal code or is it OK?
Thanks for all the answer. I now know where my problem was. However, it raises a new question:
string array initialisation
You can convert a String to integer using the parseInt() method of the Integer class. To convert a string array to an integer array, convert each element of it to integer and populate the integer array with them.
The string in JavaScript can be converted into a character array by using the split() and Array. from() functions.
Arrays.toString() method is used to return a string representation of the contents of the specified array. The string representation consists of a list of the array's elements, enclosed in square brackets (“[]”). Adjacent elements are separated by the characters “, ” (a comma followed by a space).
The c_str() and strcpy() function in C++C++ c_str() function along with C++ String strcpy() function can be used to convert a string to char array easily. The c_str() method represents the sequence of characters in an array of string followed by a null character ('\0').
Seems perfectly legal to me; char *[3]
decays to char **
, so the assignment should be valid.
Neither GCC 4.4.5 nor CLang 1.1 complains.
Although in practice array1
should decay to a pointer of type char **
, its real type is in fact char *[3]
, hence the warning.
To suppress the warning, you could try casting it explicitly:
...
(char **) array1;
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With