C expression evaluating differently on two different compilers
atmelstudio, c, gcc, language-lawyer
Solution
Both are doing it correctly. The expression `m * 1800` will be calculated as type `int`. If `int` is 32 bits, then it will be `106200`. If `int` is 16 bits, which is a perfectly acceptable way to implement a C compiler, then it's `-24872`.
Problem
I have code that is running differently between GCC and Atmel Studio: ``` uint32_t tc = 107900; int8_t m = 59; tc = tc - (m*1800); ``` On GCC, the result in `tc` is 1700, as intended. With AtmelStudio, the result in `tc` is 132772, which is not correct. The problem seems to be that the `m*1800` term is being computed with the limited precision of m with AtmelStudio. My question is, which compiler is doing it correctly? Thank you.