如何在c中指定64位整数 [英] How to specify 64 bit integers in c

查看:32
本文介绍了如何在c中指定64位整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 C 中使用 64 位整数,但我收到了关于是否可行的混合信号.

I'm trying to use 64 bit integers in C, but am getting mixed signals as to whether it should be possible.

当我执行 printf 时:

When I execute the printf:

printf("Size of long int:%d
Size of long long int:%d

",(int)sizeof(long int), (int)sizeof(long long int));

我得到的回应是:

long int 的大小:4long long int:8的大小

Size of long int:4 Size of long long int:8

这让我觉得 long long int 有 8 个字节 = 64 位.

This makes me feel that a long long int has 8 bytes = 64 bits.

但是,当我尝试声明以下变量时:

However, when I try to declare the following variables:

long long int a2 = 0x00004444;
long long int b2 = 0x000044440;
long long int c2 = 0x0000444400;
long long int d2 = 0x00004444000;
long long int e2 = 0x000044440000;
long long int f2 = 0x0000444400004;
long long int g2 = 0x00004444000044;
long long int h2 = 0x000044440000444;
long long int i2 = 0x0000444400004444;

最后 4 个变量 (f2,g2,h2,i2) 给我错误信息:

The last 4 variables (f2,g2,h2,i2) give me the error message:

警告:整数常量对于long"类型来说太大

warning: integer constant is too large for ‘long’ type

当我用 'int64_t' 替换 'long long int' 时得到相同的结果.我假设 'int64_t' 已被识别,因为它没有自己生成任何错误消息.

I get the same result when I replace 'long long int' with 'int64_t'. I assume 'int64_t' was recognized, since it didn't generate any error messages of its own.

所以,看来我的 8 字节长 long int 确实是一个 6 字节长的 long int,我不明白我在这里遗漏了什么.如果有帮助,这里是关于我的 gcc 编译器的信息:

So, it appears my 8 byte long long int is really a 6 byte long long int, and I don't understand what I'm missing here. If it's any help, here is the information on my gcc compiler:

me@ubuntu:~$ gcc -v  
Using built-in specs.  
Target: i686-linux-gnu  
Configured with: ../src/configure -v   
--with-pkgversion='Ubuntu/Linaro 4.4.4-14ubuntu5'  
--with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs   
--enable-languages=c,c++,fortran,objc,obj-c++  
--prefix=/usr   
--program-suffix=-4.4   
--enable-shared   
--enable-multiarch   
--enable-linker-build-id   
--with-system-zlib   
--libexecdir=/usr/lib   
--without-included-gettext   
--enable-threads=posix   
--with-gxx-include-dir=/usr/include/c++/4.4   
--libdir=/usr/lib   
--enable-nls   
--with-sysroot=/ -  
-enable-clocale=gnu   
--enable-libstdcxx-debug   
--enable-objc-gc   
--enable-targets=all 
--disable-werror   
--with-arch-32=i686   
--with-tune=generic   
--enable-checking=release   
--build=i686-linux-gnu   
--host=i686-linux-gnu   
--target=i686-linux-gnu  
Thread model: posix  
gcc version 4.4.5 (Ubuntu/Linaro 4.4.4-14ubuntu5)   

如果有人知道我如何(或是否)可以访问 64 位整数,我将非常感谢您的帮助.谢谢....

If anyone knows how (or if) 64 bit integers are accessible to me, I'd really appreciate any help. Thanks....

推荐答案

对特定大小的整数数据类型使用 stdint.h,并为整数文字常量使用适当的后缀,例如:>

Use stdint.h for specific sizes of integer data types, and also use appropriate suffixes for integer literal constants, e.g.:

#include <stdint.h>

int64_t i2 = 0x0000444400004444LL;

这篇关于如何在c中指定64位整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆