When I am trying to use the long long int variable with the number 123456789012345 dev C++ says there is an error and gives the message "integer constant is too large for 'long' type".
longlongint NUMBER = 123456789012345;
The number is largest than what the long type can support but it is small enough so the long long type can support it. Do someone knows what is happening here? Is it possible my version of C++ doesn't recognise the long long type? Or is it something else?
By the way, I have also tried the 64 bits integers types in the inttypes.h library, and I still got the same error message.
It might be that dev c++'s compiler doesn't recognize/support it yet. Try a different IDE with a different compiler, I recommend code::blocks, but any other might do the trick.
mobotus, I ran the code and the output was -9223372036854775808 and 9223372036854775808. What do those numbers represent? Is the limit of the compiler itself?
The issue was probably the postfix missing.
You should add a ULL for unsigneds, and I believe it's a LL for signeds, but I'm not sure, you should give that a try.
The limit could also be the compiler's.
Nothing says a compiler cannot use 128 bits for a longlong, even if the operating system natively uses 64.
Standard just says longlong >= long >= int >= short.
At least this is what I remember.
If you use C++11 and want to be certain of the size, you can use std::uint64_t .
According to http://en.cppreference.com/w/cpp/language/types , the standard also says that short has to be at least 16 bits, long has to be at least 32, and longlong has to be at least 64.
So technically, everything could be 64 bits, though I haven't heard of any implementations where this is actually the case.