gpt4 book ai didi

c - 函数的名称。它是指向该函数的指针吗?

转载 作者:行者123 更新时间:2023-12-02 05:45:19 26 4
gpt4 key购买 nike

当我们使用函数名来传递参数时,我们是否使用了指向该函数的指针?

示例:

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;
}

最佳答案

您要查找的术语是函数指示符。它不是指针类型,但大多数时候,它转换为一种类型。

引用 C11 标准,第 §6.3.2.1 章(强调我的)

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’’.

相关,来自规范第 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.

这告诉我们,在函数调用时,指示符实际上被转换为指针。

关于c - 函数的名称。它是指向该函数的指针吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41032798/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com