Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Long data type in C?

I'm a little confused as to how longs work in C.

If I ask for the maximum value of a long in Java I get a number in the quintillions. If I ask for it in C, signed or unsigned, it's in the billions.

Java is built on C... so where is the difference coming from?

I've also tried representing literals with long long values, unsigned/signed long values and long int values. None of them seem to handle numbers past the mid-billions. Why? Am I making a mistake?

like image 358
bgroenks Avatar asked Dec 24 '11 04:12

bgroenks


1 Answers

The C standard defines long to be at least as large as int. The actual size is implementation dependent. This is not the case for Java, in which long is required to be 64 bits long.

The C99 standard defines fixed size integer types like int64_t defined in stdint.h that you can use if you need fixed size integers on all platforms.

like image 199
mmx Avatar answered Sep 30 '22 04:09

mmx