int main()
{
printf("%c", "\n");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这里根据类型说明符,需要一个字符.但我们正在通过它const char *.我希望它会在代码块GNU GCC编译器中给我一个警告信息,但它没有给我任何警告和打印$字符.
为什么它没有给出任何类型的警告?
您需要启用该警告.
编译你的代码test.cpp,并添加#include <stdio.h>了printf与海湾合作委员会下4.7.2正确的警告标志:
$ gcc -c -Wformat test.cpp
test.cpp: In function 'int main()':
test.cpp:5:18: warning: format '%c' expects argument of type 'int', but argument 2 has type 'const char*' [-Wformat]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1662 次 |
| 最近记录: |