当前位置: 技术问答>linux和unix
Linux下64位整数的使用问题
来源: 互联网 发布时间:2016-05-09
本文导语: 想在Linux(ubuntu kernel 2.6.21)下使用64位整数,有如下程序片断: ... long long llNum = 0x1111222233334444; //(1) ... printf("0x%xn", llNum); //(2) ... 编译时提示(1)处"Warning: integer constant is too large for 'long' type" 运行(2)时显...
想在Linux(ubuntu kernel 2.6.21)下使用64位整数,有如下程序片断:
...
long long llNum = 0x1111222233334444; //(1)
...
printf("0x%xn", llNum); //(2)
...
编译时提示(1)处"Warning: integer constant is too large for 'long' type"
运行(2)时显示0x33334444
即使把long long换成int64_t或者long long int也不行,到底怎样才能使用64位整数呢?
...
long long llNum = 0x1111222233334444; //(1)
...
printf("0x%xn", llNum); //(2)
...
编译时提示(1)处"Warning: integer constant is too large for 'long' type"
运行(2)时显示0x33334444
即使把long long换成int64_t或者long long int也不行,到底怎样才能使用64位整数呢?
|
/*-
* file: int64.c
* auth: mymtom
* date: 2008-08-19
*/
#include
#include
int
main(void)
{
long long nLL = 0x1111222233334444LL;
int64_t n64 = 0x5555666677778888LL;
(void)printf("%llxn", nLL);
(void)printf("%llxn", n64);
return (0);
}
|
你用的就是64位,只不过你当32为打印出来。
要去掉warning:
man gcc
-Wlong-long
Warn if long long type is used. This is default. To inhibit the
warning messages, use -Wno-long-long. Flags -Wlong-long and
-Wno-long-long are taken into account only when -pedantic flag is
used.
要去掉warning:
man gcc
-Wlong-long
Warn if long long type is used. This is default. To inhibit the
warning messages, use -Wno-long-long. Flags -Wlong-long and
-Wno-long-long are taken into account only when -pedantic flag is
used.