Search code examples
cfunctionfunction-pointersfunction-calls

The name of a function. is it a pointer to that function?


When we use the name of a function to pass arguments, are we using a pointer to that function?

Example:

int foo(int a, int b);

int main(void)
{
    int a = foo(1,3); //foo() it's a pointer to the function foo()?
    return 0;
}

Solution

  • The term you're looking for is function designator. It is not a pointer type, but most of the time, it is converted to one.

    Quoting the C11 standard, chapter §6.3.2.1, (emphasis mine)

    A function designator is an expression that has function type. Except when it is the operand of the sizeof operator, the _Alignof operator,65) or the unary & operator, a function designator with type ‘‘function returning type’’ is converted to an expression that has type ‘‘pointer to function returning type’’.

    Related, from the "function call" part of the spec, chapter 6.5.2.2

    The expression that denotes the called function 92) shall have type pointer to function returning void or returning a complete object type other than an array type.

    which tells us, at the function call, the designator actually gets converted into a pointer.