您的位置:首页 > 其它

printf - warning: long long int format, int64_t arg

2014-07-10 14:58 183 查看

Method 1:

头文件<stdint.h>下:
# if __WORDSIZE == 64
typedef long int  int64_t;
# else
__extension__
typedef long long int  int64_t;
# endif
可以像头文件定义那样,判断宏,然后选择对应的输出格式:
#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;
}

Method 2:

头文件inttypes.h下:/* The ISO C99 standard specifies that these macros must only bedefined if explicitly requested. */#if !defined __cplusplus || defined __STDC_FORMAT_MACROS# if __WORDSIZE == 64# define __PRI64_PREFIX "l"# define __PRIPTR_PREFIX "l"# else# define __PRI64_PREFIX "ll"# define __PRIPTR_PREFIX# endif/* Macros for printing format specifiers. *//* Decimal notation. */# define PRId8 "d"# define PRId16 "d"# define PRId32 "d"# define PRId64 __PRI64_PREFIX "d"所以
int64_t
类型:
int64_t t;printf("%" PRId64 "\n", t);
for 
uint64_t
type:
uint64_t t;printf("%" PRIu64 "\n", t);
you can also use 
PRIx64
to print in hexadecimal.These macros are defined in
inttypes.h
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: