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_ttype:
uint64_t t;printf("%" PRIu64 "\n", t);you can also use
PRIx64to print in hexadecimal.These macros are defined in
inttypes.h
相关文章推荐
- printf函数分别在window和linux打印long long(_int64)
- Ubuntu gcc编译报错:format ‘%llu’ expects argument of type ‘long long unsigned int’, but argument 2 has type ‘__time_t’ [-Wformat=]
- __int64 与long long int
- int && long && long long && __int64
- int,long,long long,__int64 数据类型及数值范围
- jni编译时出现:warning: format '%d' expects argument of type 'int', but argument 4 has
- int,long,long long,__int64
- C语言中long long的用法 C++ __int64用法 __int64的printf问题
- C# 与数据库中字段类型 Int16(short), Int32(int), Int64(long)的取值范围、区别 。string长度
- sizeof(size_t)的疑惑||size_t sizeof long unsigned int printf max value
- int, long int, long long int, _int64範圍
- sscanf - warning unsigned int format different type arg
- int,long,long long,__int64的范围
- [C/C++]warning: format '%c' expects argument of type 'char*', but argument 2 has type 'int' [-Wforma
- __int64 与long long int
- int、long、long long、unsigned int、_int64的取值范围(与不同位数的编译器有关)
- int long long __int64的位数
- sprintf以及__int64 与long long int
- int,long,long long,__int64数据类型范围
- __int64 与 long long int