gpt4 book ai didi

c - C语言递归声明函数

转载 作者:太空狗 更新时间:2023-10-29 16:04:00 25 4
gpt4 key购买 nike

从 adream307 那里得到了一个问题,我不知道,你的呢?

I want to declare a function like this:(we named this type of function as F)

  1. the return type of F is "void"
  2. the parameter of F is a function pointer, this pointer point to afunction whose type is the same as F

can i declare a function like this?

最佳答案

不,你不能。无法表达类型,因为它会 self 重复:

void f(void g(void h(...

但是你可以编写一个接受自身的函数,没有任何问题。考虑

void f(void g()) { }

int main(void) { f(f); }

那太好了。 f的参数类型是一个函数指针(void g() 相当于这里的void (*g)()),其类型兼容f 的类型. f两个参数的函数类型兼容规则和调用中的参数 void()void (void())指定为:

If one type has a parameter type list [the call argument] and the other type is specified by a function declarator that is not part of a function definition and that contains an empty identifer list [the function parameter type], the parameter list shall not have an ellipsis terminator and the type of each parameter shall be compatible with the type that results from the application of the default argument promotions.

两种类型都满足此兼容性规则,因此函数调用定义明确。

关于c - C语言递归声明函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6168424/

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