There is a curious difference between assemblies of a small program, when compiled as a C-program or as a C++-program (for Linux x86-64).
The code in question:
int fun();
int main(){
return fun();
}
Compiling it as a C-program (with gcc -O2) yields:
main:
xorl %eax, %eax
jmp fun
But compiling it as a C++-program (with g++ -02) yields:
main:
jmp _Z3funv
I find it puzzling, that the C-version initializes the return value of the main-function with 0 (xorl %eax, %eax).
Which feature of the C-language is responsible for this necessity?
Edit: It is true that, for int fun(void); the is no initialization of the eax-register.
If there is no prototype of fun at all, i.e.:
int main(){
return fun();
}
then the C-compiler zeros the eax-register once again.