【发布时间】:2014-11-27 15:34:24
【问题描述】:
我在整个项目中都使用strlen() 调用,直到现在我在没有-Wall 编译器选项的情况下编译了我的项目。但是当我开始使用-Wall 时,我面临很多编译器警告。 80% 是 strlen char * vs const char * 警告。
我知道类型转换所有strlen() 调用。还有其他方法可以抑制以下警告吗?
./Proj.c:3126: warning: pointer targets in passing argument 1 of
'strlen' differ in signedness`
C:/staging/usr/include/string.h:397: note: expected 'const char *' but
argument is of type 'unsigned char *'`
【问题讨论】:
-
为什么你的字符串使用无符号字符指针?它们不是 const 的事实本身不会产生警告。
-
强制转换
(char*)expression。无论如何,为什么是unsigned char? -
“有没有其他方法可以抑制以下警告?”除了更改代码之外,当然还必须有一个编译器选项来抑制这种警告类型。见stackoverflow.com/questions/13400605/…