我的代码如下,并且问题也在下面解释为什么lvalue
正在发生;在c函数指针中作为一元'&'操作数需要左值
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");
}
我能够标识与不过我想要指派当我试图函数指针我得到所需的下列错误lvalue
分配作为一元操作数&
操作数
test_item test;
test.function = &display(system);
函数名后跟'()'表示调用函数。没有'()'的函数名称表示函数地址。 – Gerhardh
我不明白你要在这里做什么,但是'&display(system)'要求C为你提供一个叫做'display'的函数返回值的地址。但是,该值在处理器寄存器中返回;它根本没有地址。所以'test.function =&display(system)'这一行没有任何意义。 –
@Johnny S写test.function = **********显示; –