J
JKop
When you want to store an integer in C++, you use an integral type, eg.
int main()
{
unsigned char amount_legs_dog = 4;
}
In writing portable C++ code, there should be only two factors that
influence which integral type you choose:
A) Signedness. Do you want only positive values? Or do you want both
positive and negative values?
B) The minimum range for that type as specified by the C++ Standard.
The minimum range for "short" and "int" are identical. The following
statement is always true on all implementations:
sizeof(short) <= sizeof(int)
As this is so, why would one ever use the type "int" at all? It seem to have
no merit whatsoever. I will always use "short" in its place.
Any thoughts on this?
-JKop
int main()
{
unsigned char amount_legs_dog = 4;
}
In writing portable C++ code, there should be only two factors that
influence which integral type you choose:
A) Signedness. Do you want only positive values? Or do you want both
positive and negative values?
B) The minimum range for that type as specified by the C++ Standard.
The minimum range for "short" and "int" are identical. The following
statement is always true on all implementations:
sizeof(short) <= sizeof(int)
As this is so, why would one ever use the type "int" at all? It seem to have
no merit whatsoever. I will always use "short" in its place.
Any thoughts on this?
-JKop