int64_t警告的问题

jerry_gao_jie 2010-05-06 06:05:38
搜了一下,没搜到满意的答案,代码如下:

#include <stdio.h>
#include <stdlib.h>

int main()
{
int64_t test = 16;
printf("%lld\n", test);
return 0;
}


gcc int64.c -Wall

64位机器上编译, 有如下的警告信息,

int64.c: In function `main':
int64.c:7: warning: long long int format, int64_t arg (arg 2)

想问一下,为什么会有,怎么消除,谢谢
...全文
708 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
icansaymyabc 2010-05-06
  • 打赏
  • 举报
回复


int main()
{
int64_t test = 16;
printf("%I64d\n", test);
return 0;
}

jerry_gao_jie 2010-05-06
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 huanmie_09 的回复:]
也可以像头文件定义那样,判断宏,然后选择对应的输出格式:

C/C++ code

#include <stdio.h>
#include <stdlib.h>

int main()
{
int64_t test = 16;
# if __WORDSIZE == 64
printf("%ld\n", test);
# else
_……
[/Quote]
谢谢,搞定了
jerry_gao_jie 2010-05-06
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 thefirstz 的回复:]
不加-Wall看有没有这个警告
[/Quote]
不加是不会有的
huanmie_09 2010-05-06
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 jerry_gao_jie 的回复:]
2楼什么意思?3楼明显不是回答我的问题的.4楼,结果是正确,就是看着碍眼,想把它去掉,求方法
[/Quote]
输出类型匹配引起的。
看看int64_t的同义词类型不就明白了.
wibnmo 2010-05-06
  • 打赏
  • 举报
回复
帮顶。。
huanmie_09 2010-05-06
  • 打赏
  • 举报
回复
也可以像头文件定义那样,判断宏,然后选择对应的输出格式:

#include <stdio.h>
#include <stdlib.h>

int main()
{
int64_t test = 16;
# if __WORDSIZE == 64
printf("%ld\n", test);
# else
__extension__
printf("%lld\n", test);
# endif
return 0;
}
昵称很不好取 2010-05-06
  • 打赏
  • 举报
回复
不加-Wall看有没有这个警告
jerry_gao_jie 2010-05-06
  • 打赏
  • 举报
回复
2楼什么意思?3楼明显不是回答我的问题的.4楼,结果是正确,就是看着碍眼,想把它去掉,求方法
huanmie_09 2010-05-06
  • 打赏
  • 举报
回复
如果int64_t为long int型,自然和%lld类型不匹配.
改为
printf("%ld\n", test);
gbb21 2010-05-06
  • 打赏
  • 举报
回复
用long long 就没事了么
昵称很不好取 2010-05-06
  • 打赏
  • 举报
回复
有警告无所谓,结果正确就行~~
不放心的话可以赋值一个比较大的数,看printf结果是否越界~~
huanmie_09 2010-05-06
  • 打赏
  • 举报
回复
头文件<stdint.h>下:

# if __WORDSIZE == 64
typedef long int int64_t;
# else
__extension__
typedef long long int int64_t;
# endif

Proteas 2010-05-06
  • 打赏
  • 举报
回复
那是个结构体。
jerry_gao_jie 2010-05-06
  • 打赏
  • 举报
回复
为什么没人进来看呢?都下班了:)?

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧