gpt4 book ai didi

c - 如何将 int* 转换为 int (*p)(void)?

转载 作者:太空狗 更新时间:2023-10-29 15:53:18 24 4
gpt4 key购买 nike

我正在尝试这样做:

int (*p)(void);
int *i;
...
p = (int *(void))i;

但它会导致语法错误:

error: cast specifies function type

这里有什么问题吗?

最佳答案

在这种情况下你应该尊重错误。您不得将指向函数的指针转换为 int 指针或其他方式。这可能会导致未定义的行为。

如果你坚持的话,语法应该是:

p = (int (*)(void))i;

关于c - 如何将 int* 转换为 int (*p)(void)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6816938/

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