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

后端 未结 8 1040
萌比男神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:54

    You should keep in mind that such code may crash depending on compiler. For example, clang generates ud2 instruction at the end of such function and your app will crash at run-time.

提交回复
热议问题