In the following C code:
#include <stdio.h>
int main(void){getchar();}
It produces the following asm:
main:
push rbp
mov rbp, rsp
# no extra instruction here when header is included
call getchar
mov eax, 0
pop rbp
ret
However, if I don't include stdio.h
in the file, then it still compiles, but adds in what looks like a random mov eax, 0
instruction:
Here is Compiler Explorer: https://godbolt.org/z/3fTcss. Is this just part of "undefined behavior", or is there a particular reason that the instruction before call getchar
is added there?