本文介绍了字符串数组转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下的code:
char *array1[3] =
{
"hello",
"world",
"there."
};
struct locator_t
{
char **t;
int len;
} locator[2] =
{
{
array1,
10
}
};
它编译与海湾合作委员会-Wall -ansi -pedanticOK。但是,与其他工具链(罗利),它抱怨
It compiles OK with "gcc -Wall -ansi -pedantic". But with another toolchain (Rowley), it complains about
warning: initialization from incompatible pointer type
在哪里字符** t是一行。这是确实违法code或者是OK?
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:
推荐答案
似乎完全合法的我。 的char * [3]
衰减到的char **
,所以分配应该是有效的。
Seems perfectly legal to me; char *[3]
decays to char **
, so the assignment should be valid.
无论是GCC 4.4.5,也不铛1.1抱怨。
Neither GCC 4.4.5 nor CLang 1.1 complains.
这篇关于字符串数组转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!