I work a lot in embedded systems and I'm just curious if anyone knows if it's generally more efficient to keep variables the same type - specifically signed or unsigned and size - when doing arithmetic operations. Or does it not matter because of compiler kungfu?
For example, is either better:
// These are member variables
int32_t output;
uint16_t alpha; // <- Different type
// This is called by a timer
step(int32_t input) {
output = (input - output) * alpha + output;
}
or
// These are member variables
int32_t output;
int32_t alpha; // <- Same type
// This is called by a timer
step(int32t input) {
output = (input - output) * alpha + output;
}