字符串数组转换

编程入门 行业动态 更新时间:2024-10-25 08:21:34
本文介绍了字符串数组转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有以下的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.

更多推荐

字符串数组转换

本文发布于:2023-11-04 05:41:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1557099.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   字符串

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!