Function Names as Function Pointers: A Design Rationale
In C, using function names as function pointers is equivalent to applying the address-of operator to the function name. This behavior may seem inconsistent with other parts of the language and raises questions about its design rationale.
The ANSI C90 Rationale document provides insights into this design decision:
(&f)(); // Explicit address-of operator f(); // Implicit conversion to function pointer (*f)(); // Deference of a function pointer (**f)(); // Deference twice (***f)(); // Deference three times
Regarding the absence of implicit conversion from function type to pointer type in return contexts, the explanation lies in the concept of "return type decoration." In C, function return types are part of the function's signature and cannot be modified. Thus, a function cannot implicitly return a pointer to itself.
The above is the detailed content of Why are Function Names Used as Function Pointers in C?. For more information, please follow other related articles on the PHP Chinese website!