Why does this void function return an integer, although although there is no return statement?

This code prints 5, although I am not returning anything to m().

#include <stdio.h>
int abc();
int main(){
    printf("%d", m());
}

int abc(){
    return 5;
}

void m(){
    abc();
}

The function is also invalid. So can someone explain why 5 is printed?

+4
source share
2 answers

C implementations often use functions to return a value by placing the value in the processor register intended for that value. So what could happen is:

  • To return 5, abcput 5 in this register.
  • Since it mdoes not return a value, it does not change case.
  • main m, , . abc 5, m , main 5 .

C, , , , .

, C , m, main :

  • , int, ( C 1999 C)
  • - , ( C).
+7

C undefined ( , , ) ( ).

, int /. abc . m , m void . main , m ( main m int) 5.

+3

Source: https://habr.com/ru/post/1695278/


All Articles