int f(int x, int y) {
return x << y;
}
This is undefined for SOME values of y, namely those bigger than 31 (on platforms where int is 32 bit; adjust where different).This is caused by two facts:
a) The arithmetic operation should be compiled to a hardware shift instruction where possible
b) Different architectures do different things when shifting by an amount bigger than the word size:
- on ARM, the "y" operand is evaluated mod 32
- on x86, if y is greater than 31, the result is 0