I'm confused with range of values of Int variable in C.
I know that a 32bits unsigned int have a range of: 0 to 65,535. So long has 0 to 4,294,967,295
This is fine in 32bits machine. But now in 64bits machines all thing keep the same? Or maybe my int capacity is different?
I understand this questions as newbie, but I'm really confused. This method signature is not helping too. :)
unsigned long long int atomicAdd(unsigned long long int* address, unsigned long long int val);
A signed integer is a 32-bit datum that encodes an integer in the range [-2147483648 to 2147483647]. An unsigned integer is a 32-bit datum that encodes a nonnegative integer in the range [0 to 4294967295].
A 64-bit signed integer. It has a minimum value of -9,223,372,036,854,775,808 and a maximum value of 9,223,372,036,854,775,807 (inclusive).
Holds signed 64-bit (8-byte) integers ranging in value from -9,223,372,036,854,775,808 through 9,223,372,036,854,775,807 (9.2... E+18).
Windows: long and int remain 32-bit in length, and special new data types are defined for 64-bit integers.
In C and C++ you have these least requirements (i.e actual implementations can have larger magnitudes)
signed char: -2^07+1 to +2^07-1 short: -2^15+1 to +2^15-1 int: -2^15+1 to +2^15-1 long: -2^31+1 to +2^31-1 long long: -2^63+1 to +2^63-1
Now, on particular implementations, you have a variety of bit ranges. The wikipedia article describes this nicely.
No, int
in C is not defined to be 32 bits. int
and long
are not defined to be any specific size at all. The only thing the language guarantees is that sizeof(char)<=sizeof(short)<=sizeof(long)
.
Theoretically a compiler could make short
, char
, and long
all the same number of bits. I know of some that actually did that for all those types save char
.
This is why C now defines types like uint16_t
and uint32_t
. If you need a specific size, you are supposed to use one of those.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With