About Pointers To Functions in function declarations

后端 未结 4 1705
后悔当初
后悔当初 2020-12-01 18:02
#include
#include

int fun1()
{
    printf(\"I am fun1.\");
    return 0;
}

int fun2(int fun())
{
    fun();
    return 0;
}

int mai         


        
4条回答
  •  栀梦
    栀梦 (楼主)
    2020-12-01 18:53

    These two function definitions are equivalent in C:

     int fun2(int fun()) { ... }
    

    and

     int fun2(int (*fun)()) { ... }
    

    In the first function the parameter is adjusted to a function pointer. See C Standard paragraph:

    (C99, 6.7.5.3p8) "A declaration of a parameter as ‘‘function returning type’’ shall be adjusted to ‘‘pointer to function returning type’’, as in 6.3.2.1."

提交回复
热议问题