+ 1
What is the diff b/w 16,32,64 bit register in c regarding datatype sizes when we are using sizeof operator???
As we can see in a 16 bit register we are getting int = 2bytes,float=4bytes,char=1byte(depending on the compiler) but when It comes to a 32,64 bit register why it is changing It's bytes
2 Antworten
+ 2
It has nothing to do with the register size, the compiler alone decides the integer size.
You can use stdint for int8_t, int16_t, int32_t and int64_t, if you want 1, 2, 4 and 8 byte integers. C originally was used on 16-bit and 32-bit systems. It generally made sense to use the register size for the common integer width (int), so int was either 16 or 32 bits (2 or 4 bytes), with char, short, long, representing fixed width integers (1, 2 and 4 bytes). Later, long long was added for 64 bits.
So, so far what we have is:
* char (8 bits)
* short (16 bits)
* int (16 or 32 bits, register size)
* long (32 bits)
* long long (64 bits)
But then the dichotomy changed from 16/32 bit systems to 32/64 bits. Because the stardars say int is shorter then long, so you can't have int be 64 bits when long is 32, and you can't make long 64 too, because you lose a name for 32 bits. So instead we have this:
* char (8 bits)
* short (16 bits)
* int (32 bits)
* long (32 or 64 bits, register size)
* long long (64 bits)
0
Except on Windows, where long is always 32 bits.