Why and how does GCC compile a function with a missing return statement?

后端 未结 8 1041
萌比男神i
萌比男神i 2020-12-01 23:57
#include 

char toUpper(char);

int main(void)
{
    char ch, ch2;
    printf(\"lowercase input : \");
    ch = getchar();
    ch2 = toUpper(ch);
             


        
8条回答
  •  被撕碎了的回忆
    2020-12-02 00:45

    Essentially, c is pushed into the spot that should later be filled with the return value; since it's not overwritten by use of return, it ends up as the value returned.

    Note that relying on this (in C, or any other language where this isn't an explicit language feature, like Perl), is a Bad Idea™. In the extreme.

提交回复
热议问题