On this webpage, the comments on unsigned short state:
Used to reduce memory usage (although the resulting executable may be larger and probably slower as compared to using int
Why is this?
I think the wording "probably slower" is too hard.
A theoretical fact is:
Calculations are done with at least int
size, e.g.
short a = 5;
short b = 10;
short c = a + b;
This code snippet contains 3 implicit conversions. a
and b
are converted to int
and added. The result is converted back from int
to short
. You can't avoid it. Arithmetic in C++ uses at least int
size. It's called integer promotion.
In practice most conversions will be avoided by the compiler. And the optimizer will also remove many conversions.
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