我是靠谱客的博主 贤惠书包,最近开发中收集的这篇文章主要介绍C: 警告:unknown conversion type character ‘
’ in format; sizeof,size_t,觉得挺不错的,现在分享给大家,希望可以做个参考。
概述
sizeof.c:10:27: warning: unknown conversion type character ‘x0a’ in format [-Wformat=]
printf(“sizeof(double)=%zn”, sizeof(double));
^~
这里是说,%z的后面还需要跟一个类型转换符,比如u/d 之类的;
但是z后面跟了一个换行符;
编译器也是的,既然%z就标识着是size_t的类型,这个类型的数据类型也就固定了,还要别的转换符干啥用。
而且这个size_t的检测,静态代码检查工具和编译器的检查方式还不一样。
https://www.gnu.org/software/libc/manual/html_node/Integer-Conversions.html
#include <stdio.h>
int main()
{
int a[3];
printf("sizeof(double)=%dn", sizeof(double));
printf("sizeof(double)=%ldn", sizeof(double));
printf("sizeof(double)=%un", sizeof(double));
printf("sizeof(double)=%lun", sizeof(double));
printf("sizeof(double)=%zn", sizeof(double));
printf("sizeof(double)=%Zn", sizeof(double));
printf("sizeof(double)=%zun", sizeof(double));
printf("sizeof(double)=%zlun", sizeof(double));
printf("sizeof(double)=%Zun", sizeof(double));
printf("sizeof(double)=%mn", sizeof(double));
return 1;
}
[root@10 test]# gcc -Wall sizeof.c
sizeof.c: In function ‘main’:
sizeof.c:6:26: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long unsigned int’ [-Wformat=]
printf("sizeof(double)=%dn", sizeof(double));
~^ ~~~~~~~~~~~~~~
%ld
sizeof.c:8:26: warning: format ‘%u’ expects argument of type ‘unsigned int’, but argument 2 has type ‘long unsigned int’ [-Wformat=]
printf("sizeof(double)=%un", sizeof(double));
~^ ~~~~~~~~~~~~~~
%lu
sizeof.c:10:27: warning: unknown conversion type character ‘x0a’ in format [-Wformat=]
printf("sizeof(double)=%zn", sizeof(double));
^~
sizeof.c:10:9: warning: too many arguments for format [-Wformat-extra-args]
printf("sizeof(double)=%zn", sizeof(double));
^~~~~~~~~~~~~~~~~~~~~
sizeof.c:11:27: warning: unknown conversion type character ‘x0a’ in format [-Wformat=]
printf("sizeof(double)=%Zn", sizeof(double));
^~
sizeof.c:11:9: warning: too many arguments for format [-Wformat-extra-args]
printf("sizeof(double)=%Zn", sizeof(double));
^~~~~~~~~~~~~~~~~~~~~
sizeof.c:13:27: warning: unknown conversion type character ‘l’ in format [-Wformat=]
printf("sizeof(double)=%zlun", sizeof(double));
^
sizeof.c:13:9: warning: too many arguments for format [-Wformat-extra-args]
printf("sizeof(double)=%zlun", sizeof(double));
^~~~~~~~~~~~~~~~~~~~~~~
sizeof.c:15:9: warning: too many arguments for format [-Wformat-extra-args]
printf("sizeof(double)=%mn", sizeof(double));
^~~~~~~~~~~~~~~~~~~~~
sizeof.c:5:6: warning: unused variable ‘a’ [-Wunused-variable]
int a[3];
^
最后
以上就是贤惠书包为你收集整理的C: 警告:unknown conversion type character ‘ ’ in format; sizeof,size_t的全部内容,希望文章能够帮你解决C: 警告:unknown conversion type character ‘ ’ in format; sizeof,size_t所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复