常见gcc编译警告汇总
1、warning: control reaches end of non-void function
老友记剧本
⽤gcc编译⼀个程序的时候出现这样的警告:
高中英语新课程标准warning: control reaches end of non-void function
它的意思是:控制到达⾮void函数的结尾。就是说你的⼀些本应带有返回值的函数到达结尾后可能并没有返回任何值。这时候,最好检查⼀下是否每个控制流都会有返回值。
2、warning: passing argument 4 of 'snd_pcm_hw_params_t_rate' makes integer from pointer without a cast [-Wint-conversion]
mid autumn
它的意思是:传⼊ “snd_pcm_hw_params_t_rate” 的参数4将使指针为整数,⽽不进⾏转换[-Wint-conversion]。就是说函数的第四个参数应该传⼊整数,但是现在传⼊了⼀个指针,并且未进⾏类型转换。
3、warning: argument to 'sizeof' in 'strncpy' call is the same expression as the source; did you mean to u the size of the destination? [-Wsizeof-pointer-memaccess]
strncpy(cardName, pcmMgr->cardName, sizeof(pcmMgr->cardName)); 应该为 strncpy(cardName, pcmMgr->cardName, sizeof(cardName));
4、warning: assignment to 'long unsigned int *' from 'long unsigned int' makes pointer from integer without a cast [-Wint-conversion]
busy是什么意思
意思是:将 ‘long unsigned int’ 赋值给 ‘long unsigned int *’ ,即将整型转换为指针,没有加强制类型转换。
unsigned long *ubuffer = xxx;
unsigned long *pbuffer = NULL;
pbuffer = ubuffer[1]; 应该为 pbuffer = (unsigned long *)ubuffer[1];
pass是什么5、warning: comparison of unsigned expression < 0 is always fal [-Wtype-limits]
警告:⽆符号表达式的⽐较<0始终为fal。
staroom
6、warning: suggest parenthes around assignment ud as truth value [-Wparenthes]雅思辅导
羊的英文while(entry=readdir(dir))
{...}
adm是什么意思警告:建议在赋值周围使⽤圆括号作为真值。在C语⾔中,⾮0代表TRUE,反之为FALSE。entry值是⽤于最后的判断⽤的,但是由于长期的编程实践告诉我们,⼈们经常在 “=” 和 “” 的使⽤上出现⼿误,所以gcc编译器为此要求我们明确地告诉编译器它是 “=” ⽽不是 "",是故意,⽽⾮⼿误。
7、src/subProbe.c:297:9: error: ‘strncpy’ output truncated before terminating nul copying 3 bytes from a string of the same length [-Werror=stringop-truncation]
strncpy((char *)lang[0], "und", 3);
使⽤gcc-8版本会编译报错,修改为 strncpy((char *)lang[0], "und", 4);,编译正确。
8、src/subProbe.c:190:12: error: ‘strncpy’ output may be truncated copying 2 bytes from a string of length 31 [-Werror=stringop-truncation]
strncpy((char*)lang[*num], (const char*)language, 2);
使⽤gcc-8版本会编译报错,修改为 memcpy((char*)lang[*num], (const char*)language, 2);,编译正确。ofwhich
问题中strncpy的⽤法实际上是正确的(在缓冲区中对某些字符进⾏左对齐,⽤空字节右填充),但是错误是因为这个函数经常被⼈误⽤试图复制以空结束的字符串。