gpt4 book ai didi

c - c 函数指针中需要左值作为一元 ‘&’ 操作数

转载 作者:行者123 更新时间:2023-11-30 19:57:22 27 4
gpt4 key购买 nike

我的代码如下,下面还解释了为什么会发生左值

typedef struct test_item
{
char id[MENU_NAME_LEN + NULL_SPACE];
MenuFunction function;
} test_item;

 typedef void (*MenuFunction)(VmSystem *);

void display(VmSystem * system)
{
printf("test");
}

我可以用我想要的值分配 ID,但是当我尝试分配函数指针时,我收到以下错误 lvalue required as unary & operand

test_item test;
test.function = &display(system);

最佳答案

你的意思是:

test.function = display;

display后面的()表示调用该函数。仅 display 将计算为指向该函数的指针。不需要&display

关于c - c 函数指针中需要左值作为一元 ‘&’ 操作数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46197162/

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