首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 操作系统 > UNIXLINUX >

Linux下64位整数的使用有关问题

2012-02-11 
Linux下64位整数的使用问题想在Linux(ubuntu kernel 2.6.21)下使用64位整数,有如下程序片断:...long long

Linux下64位整数的使用问题
想在Linux(ubuntu kernel 2.6.21)下使用64位整数,有如下程序片断:

...
long long llNum = 0x1111222233334444; //(1)
...
printf("0x%x\n", llNum); //(2)
...

编译时提示(1)处"Warning: integer constant is too large for 'long' type"
运行(2)时显示0x33334444
即使把long long换成int64_t或者long long int也不行,到底怎样才能使用64位整数呢?


[解决办法]

C/C++ code
/*- * file: int64.c * auth: mymtom * date: 2008-08-19 */#include <sys/types.h>#include <stdio.h>intmain(void){        long long       nLL = 0x1111222233334444LL;        int64_t         n64 = 0x5555666677778888LL;        (void)printf("%llx\n", nLL);        (void)printf("%llx\n", 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.


热点排行
Bad Request.