num2 is obviously right, num1 isn't. The corresponding case for ints doesn't seem to have the same problem. sizeof() shows they are both 4 bytes, so it shouldn't be overflowing. However, if I do 10 * 160 * 20 (== 32000) it works fine, so I'm deducing the existence of an intermediate int somewhere in the compiler....
The simplest possible example above was posted after a couple hours of tearing my hair out. Later I realized that even assigning 10 * 60 * 60 to num1 at runtime also had the problem. So it may not be a compiler issue, but it's still whack.
I guess my C is rustier than I thought. Still, it's a little odd that I got away with 36000 with no 'L' but I didn't get away with 10 * 60 * 60. Also, gcc-avr (if that's the culprit) must be less forgiving than regular gcc, since I tried this in a regular program and it worked fine. Are warnings suppressed by the Arduino IDE?
Still, it's a little odd that I got away with 36000 with no 'L' but I didn't get away with 10 * 60 * 60.
Well, 36000 is > 32767 which is the largets int you can have, so gcc probably just assumed it was a long since it wouldn't fit in an int (this is just a guess on my part).
I tried this in a regular program and it worked fine.
The size of an int vs. a long int may be different on a different architecture. Your computer most likely has ints and long ints the same size (32 bits), whereas the AVR has 16 bit ints and 32 bit long ints.