Candy wrote:
Guys - Microsoft did not define nor invent C++! Nor do they hold any authority over it whatsoever.
Try ISO 9899 or ISO 14882.
For your information:
Char must hold at least 256 different values, short must hold at least 65536 different values, int must be larger than or equal to short, long must be larger than or equal to int and long long must be larger than or equal to long. Note that long long is only defined in C99, so in C89 or in c++ there is no long long (which should explain the warnings/errors you get when turning on warnings for c++ code).
So, all in all, you can't assume you can add two shorts and fit it in a long long.
Sorry if my post was misleading, I know that is the MS interpretation of the standard, and not a link to the standard itself. But, it states the exact same info you have stated...
"Type short int (or simply short) is an integral type that is larger than or equal to the size of type char, and shorter than or equal to the size of type int."
"Type int is an integral type that is larger than or equal to the size of type short int, and shorter than or equal to the size of type long."
"Type long (or long int) is an integral type that is larger than or equal to the size of type int."
"Type long long Larger than an unsigned long."
This is consistant with the standard, even if it is a m$ document. The other parts of the document are specific to their implementation (at the bottom where it says sizes of fundamental types, those are specific to msvc), and can be different under other compilers and still fit the above descriptions. Notice on the page however, it actually states Microsoft Specific before that section, and End Microsoft Specific at the bottom, so I figured it'd be an easy to read link for people. We do agree that you cannot assume sizes based on 'standard' data types, which is why I define my own, and use the # of bits in the name, so anybody reading will always know it's size and type. s8 = signed 8-bit, u8 = unsigned 8bit, sX = signed X bits, uX = unsigned X bits. Anybody reading my code will easily know what the size of all data types being passed around are.