I'm working on project involving c programming for my mathematics course at university. I need to be able to handle large integers, larger than those that can be stored in a 'long int' datatype. So I tried using 'long long int', but if I try something like this:
long long int number;
number = 10000000000;
Then the error message says 'error: integer constant too large for "long" type'.
I've tried other datatypes like '___int64' and 'int_64t' I've tried including all the standard c libraries and I still get the same problem.
Strangely, when I try 'printf("LLONG_MAX = %lld\n", LLONG_MAX);'
, I get this:
LLONG_MAX = -1
I'm using Codeblocks 8.02 on windows xp, but I'm not sure what version of gcc compiler is installed since I'm using network computers on campus and I don't have permission to access the main filesystem. I don't want to have to bring my laptop into campus everyday. Please help! Thanks
When the compiler is compiling your C file and comes across an integer or floating point constant it needs to assign it a type. It will implicitly choose a default type for you. You can explicitly set the type by providing the compiler the integer suffix. An integer suffix can tell the compiler if it's a long, long long, or unsigned type.
Floating point types also have this situation. A type can either be a float, a double or a long double. A floating point type usually defaults to double.
Add an ll
at the end of your integer constant.
In Microsoft environment use printf with this syntax :
__int64 i64 = 10000000000; unsigned __int64 u64 = 10000000000000000000; printf ( "%I64d\n", i64 ); printf ( "%I64u\n", u64 ); printf ( "%I64d\n", u64 ); <-- note this typo
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