Reputation: 1702
I have some issue when compiling in ARM cross compiler with a variable of type unsigned long long
The variable represents partition size (~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.
Does anyone know why the compiler store it as 32-bits?
My mistake, the value is set in C using the following calculation:
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! Casting solved this issue for me.
Upvotes: 1
Views: 312
Reputation: 1702
My mistake........ the value is set in C using the following calcualtion:
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 & f_frsize are only 32 bits, and the compiler does not automatically cast them to 64bits!
Casting solved this issue for me.
Upvotes: 2
Reputation: 19864
The below code prints the whole 64 bits.Try printing it using %llu
main()
{
unsigned long long num = 4611111275421987987;
printf("%llu\n",num);
}
Upvotes: 1