鱼C论坛

 找回密码
 立即注册
查看: 1700|回复: 1

[已解决]C

[复制链接]
发表于 2017-5-18 18:22:06 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
请问一下在ubuntu14.04上出现了一下报错信息是什么情况?
代码和报错信息如下:
  1. #include <stdio.h>

  2. int main()
  3. {
  4.         int i;
  5.         char j;
  6.         float k;

  7.         i = 123;
  8.         j = 'C';
  9.         k = 3.14;

  10.         printf("size of int is %d\n", sizeof(int));
  11.         printf("size of i is %d\n", sizeof(i));
  12.         printf("size of char is %d\n", sizeof(char));
  13.         printf("size of j is %d\n", sizeof j);
  14.         printf("size of float is %d\n", sizeof(float));
  15.         printf("size of k is %d\n", sizeof k);

  16.         return 0;
  17. }
复制代码




在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:28:22
本帖最后由 超凡天赐 于 2017-5-18 18:29 编辑

提示就是让你把类型改为无符号长整型。
我认为你这个只是警告。我猜和国际标准有关。你可以查一下c99和c11标准。下面代码应该不会警告。
  1. #include <stdio.h>
  2. int main()
  3. {
  4.     int i;
  5.     char j;
  6.     float k;
  7.     i = 123;
  8.     j = 'C';
  9.     k = 3.14;
  10.     printf("size of int is %lu\n", sizeof(int));
  11.     printf("size of i is %lu\n", sizeof(i));
  12.     printf("size of char is %lu\n", sizeof(char));
  13.     printf("size of j is %lu\n", sizeof j);
  14.     printf("size of float is %lu\n", sizeof(float));
  15.     printf("size of k is %lu\n", sizeof k);
  16.     return 0;
  17. }
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2017-5-18 18:28:22 | 显示全部楼层    本楼为最佳答案   
本帖最后由 超凡天赐 于 2017-5-18 18:29 编辑

提示就是让你把类型改为无符号长整型。
我认为你这个只是警告。我猜和国际标准有关。你可以查一下c99和c11标准。下面代码应该不会警告。
  1. #include <stdio.h>
  2. int main()
  3. {
  4.     int i;
  5.     char j;
  6.     float k;
  7.     i = 123;
  8.     j = 'C';
  9.     k = 3.14;
  10.     printf("size of int is %lu\n", sizeof(int));
  11.     printf("size of i is %lu\n", sizeof(i));
  12.     printf("size of char is %lu\n", sizeof(char));
  13.     printf("size of j is %lu\n", sizeof j);
  14.     printf("size of float is %lu\n", sizeof(float));
  15.     printf("size of k is %lu\n", sizeof k);
  16.     return 0;
  17. }
复制代码

评分

参与人数 1荣誉 +5 鱼币 +5 贡献 +5 收起 理由
人造人 + 5 + 5 + 5 支持楼主!

查看全部评分

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-26 00:40

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表