C: warning: format not a string literal and no format arguments

如何打印出这个警告

[root@vmtca-2003 test]# gcc -Wall -Wformat -Wformat-nonliteral printf.c
printf.c: In function ‘main’:
printf.c:5:2: warning: format not a string literal and no format arguments [-Wformat-nonliteral]
printf(a);
^~~~~~

作用

警告用户要注意,传进来的格式串不是常量,这样编译器无法做下面这个警告的检查。
如果不做格式检查,用户可能就发现不了下面这个错误,导致bug的产生。
printf.c:6:17: warning: format ‘%s’ expects a matching ‘char *’ argument [-Wformat=]
printf(“abcde %s”);
~^

猜你喜欢

转载自blog.csdn.net/qq_36428903/article/details/125322622