C
请问一下在ubuntu14.04上出现了一下报错信息是什么情况?代码和报错信息如下:
#include <stdio.h>
int main()
{
int i;
char j;
float k;
i = 123;
j = 'C';
k = 3.14;
printf("size of int is %d\n", sizeof(int));
printf("size of i is %d\n", sizeof(i));
printf("size of char is %d\n", sizeof(char));
printf("size of j is %d\n", sizeof j);
printf("size of float is %d\n", sizeof(float));
printf("size of k is %d\n", sizeof k);
return 0;
}
在LINUX下运行报错信息如下:
root@tc:~/C/s1e6# gcc work1.c -o work1
work1.c: In function ‘main’:
work1.c:12:2: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long unsigned int’ [-Wformat=]
printf("size of int is %d\n",sizeof(int));
^
work1.c:13:2: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long unsigned int’ [-Wformat=]
printf("size of i is %d\n",sizeof(i));
^
work1.c:14:2: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long unsigned int’ [-Wformat=]
printf("size of char is %d\n",sizeof(char));
^
work1.c:15:2: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long unsigned int’ [-Wformat=]
printf("size of j is %d\n",sizeof(j));
^
work1.c:16:2: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long unsigned int’ [-Wformat=]
printf("size of float is %d\n",sizeof(float));
^
work1.c:17:2: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long unsigned int’ [-Wformat=]
printf("size of k is %d\n",sizeof k);
^ 本帖最后由 超凡天赐 于 2017-5-18 18:29 编辑
提示就是让你把类型改为无符号长整型。
我认为你这个只是警告。我猜和国际标准有关。你可以查一下c99和c11标准。下面代码应该不会警告。
#include <stdio.h>
int main()
{
int i;
char j;
float k;
i = 123;
j = 'C';
k = 3.14;
printf("size of int is %lu\n", sizeof(int));
printf("size of i is %lu\n", sizeof(i));
printf("size of char is %lu\n", sizeof(char));
printf("size of j is %lu\n", sizeof j);
printf("size of float is %lu\n", sizeof(float));
printf("size of k is %lu\n", sizeof k);
return 0;
}
页:
[1]