简体   繁体   English

64位变量存储为32位

[英]64 bit variable is stored as 32-bit

I have some issue when compiling in ARM cross compiler with a variable of type unsigned long long 在ARM交叉编译器中使用unsigned long long类型的变量进行编译时遇到了一些问题

The variable represents partition size (~256GBytes). 该变量表示分区大小(~256GBytes)。 I expect it to be stored as 64-bit, but on printing it using %lld , or even trying to print it as Mega bytes (value/(1024*1024*1024)) , I always see the only 32-bit of the real value. 我希望它存储为64位,但在使用%lld打印它,或者甚至尝试将其打印为Mega字节(value/(1024*1024*1024)) ,我总是看到它的唯一32位真正的价值。

Does anyone know why the compiler store it as 32-bits? 有谁知道为什么编译器将它存储为32位?

Edit: 编辑:

My mistake, the value is set in C using the following calculation: 我的错误,使用以下计算在C中设置值:

partition_size = st.f_bsize*st.f_frsize;
struct statvfs { unsigned long int f_bsize; unsigned long int f_frsize; ...}

The issue is that f_bsize and f_frsize are only 32 bits, and the compiler does not automatically cast them to 64bits! 问题是f_bsizef_frsize只有32位,编译器不会自动将它们转换为f_frsize位! Casting solved this issue for me. Casting为我解决了这个问题。

My mistake........ the value is set in C using the following calcualtion: 我的错误........使用以下计算方法在C中设置值:

partition_size = st.f_bsize*st.f_frsize; partition_size = st.f_bsize * st.f_frsize;

struct statvfs { unsigned long int f_bsize; struct statvfs {unsigned long int f_bsize; unsigned long int f_frsize;...} unsigned long int f_frsize; ...}

The issue is that f_bsize & f_frsize are only 32 bits, and the compiler does not automatically cast them to 64bits! 问题是f_bsize&f_frsize只有32位,编译器不会自动将它们转换为64位!

Casting solved this issue for me. Casting为我解决了这个问题。

The below code prints the whole 64 bits.Try printing it using %llu 下面的代码打印整个64位。尝试使用%llu打印它

  main()
    {
    unsigned long long num = 4611111275421987987;
    printf("%llu\n",num);
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM