我的代碼如下,並且問題也在下面解釋爲什麼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 = **********顯示; –