Really cool, it surprised me to see even trivial code give very different results in gcc,icc and clang.
int retNum(int num, int num2) {
return (num * num2)/num;
}
gives this in clang
retNum(int, int): # @retNum(int, int)
mov eax, esi
ret
While icc and gcc give
retNum(int, int):
mov eax, esi
imul eax, edi
cdq
idiv edi
ret
retNum(int, int):
imul esi, edi
mov eax, esi
cdq
idiv edi
ret
The clang version at first sight seem right. But then thinking about it this is integer math.
4/3 := 1
1 * 3 := 3
leads to
3 != 4
I believe gcc and icc returning 3 there is correct, while clang returning 4 is not. Maybe someone more C/int versed
can tell us which are acceptable (knowing C both might be ok)