Long int and int have the same max value?

Nov 22, 2014 at 9:20am
So I recently started programming and in the lesson i'm on it is teaching about integer types. I found the use of int, and how to use INT_MAX to find the max output of int. But it also said to use long int for something larger. As i created my code using long int, and adding another digit to my number i got a warning staying "overflow in implicit constant conversion [-Woverflow]" And when i use the LONG_MAX to find the max, it comes out to be the exact same as the INT_MAX. Does anyone know why this happens? Is it an issue with my compiler?



Nov 22, 2014 at 9:32am
Does anyone know why this happens?
Because long can be the same size as int.
Types like char, short, int, long, long long do not have set size. They have constraints on both relations between them (for example no type can be larger than type after it in posted sequence and sizeof char is always 1) and minimum size (short is at least 16 bit long).
http://en.cppreference.com/w/cpp/language/types
Scroll down to Propertires and look at the table provided.
Nov 22, 2014 at 9:36am
Thank you for clearing that up for me. This video I am learning from made and Int and then just made the number larger and switched to long int. And when i did the same thing I got the error and though I was either being stupid or that my compiler was just wrong in some way. So this is a common thing then and i shouldn't be concerned?
Nov 22, 2014 at 9:39am
No. If you really need more than 32 bit, use long long type.
Topic archived. No new replies allowed.