With the following code:
#include <stdint.h>
uint16_t test() {
uint16_t a = 1000;
uint16_t b = 1000;
uint16_t c = 100;
return (a * b) / c;
}
A compiler targeting a 32bit machine will return 10000, but one targeting a 16 bit machine will return 169. The behavior is explained by C's integer promotion rules.
This is a problem when unit testing firmware for a 8 or 16 bit machine on a desktop PC.
Right now, either casting every multiplication or putting it inside a function returning the same type are the only options I can think of. Ideally some compiler switch would exist, but I haven't seen one.
Happy with a solution for either GCC, Clang or MSVC.