posted 13 years ago
I wrote this basic, basic, subroutine to learn a bit about promotions and literals:
OK, I am confused. The error at 1) I get: The result of an integral arithmetic expression has the default width of an int, 4 bytes, the short can not handle it.
Why does 2) Work? Is it because += is an operator, so the short (s) gets promoted? But that doesn't really make sense as there is an assignment to a variable that is still a short?
3) Also isn't the default width of an arithmetic expression like 4 +5 an int, even though the result can easily fit within a short?
4) Is obvious. Needs and F/f.
5) is much the same as 3).
6) I get: Default width of a floating point opeation is a double. See 1). But I am still not clear as to why 1) and 6) fail and 2) does not. I did some very basic poking around on this site, and did not easily find the answer. Any help with explanations or sources would be appreciated.
Thanks