读书人

请问gcc编译下的几个警告该如何去除

发布时间: 2012-05-21 18:04:41 作者: rapoo

请教gcc编译下的几个警告该怎么去除,
gcc编译下的几个警告怎么去除
1.报165: warning: too many arguments for format
code:
#define OutLineNum(row, line, item) {、
char buf[60], buf2[10];\
if (item) {
sprintf(buf2, "(%d)", (item));\
sprintf(buf, "%5s", buf2);}\
else{
sprintf(buf, " ", (line)+1, (item));}\
}
调用处:
int line;
static int firstItemInCurrentPage=0;
OutLineNum(line, (line+firstItemInCurrentPage), 0); //此行报warning错误,不知道该怎么解决

2.报warning: embedded '\0' in format
snprintf(strtmp, sizeof(strtmp), ">\000");//此行报警告

3.报warning: array subscript has type 'char'
char string1[30];
char string2[30]="测试%s %2d测试%-11s";
char string3[10]="测试";
char string4[10]="测试";

static unsigned char WaiShe[MAX_OUTSIDEDEVICE];
unsigned char OutDeviceTypeData[MaxOutDeviceType][DeviceNameLen];

sprintf(string1, string2, string4, WaiShe[0],OutDeviceTypeData[id]);//此行报警告


[解决办法]
编译器给出warning,说明你的代码有问题。
sprintf(buf, " ", (line)+1, (item));},
没有指定格式符,却使用了2个参数

snprintf(strtmp, sizeof(strtmp), ">\000");//此行报警告,
字符串本来就包含结束符\0,为什么你还要加上\000

sprintf(string1, string2, string4, WaiShe[0],OutDeviceTypeData[id]);//此行报警告
WaiShe[0]是 char类型,你却指定格式符 %d
OutDeviceTypeData[id] 是char型,你却指定%s

[解决办法]
warning: array subscript has type 'char'

OutDeviceTypeData[id]检查id是否为char
[解决办法]
utDeviceTypeData[id]检查id是否

读书人网 >C语言

热点推荐