RT,最近看到 LIST_HEAD有個宏控可以初始化結構體,然后自己就嘗試著在 vs2010試了下,發現無論怎樣都編不過,還請大佬解答下,為什么?
錯誤資訊如下:
1> error C2086: “list_head my_list”: 重定義
老是說重定義,真的沒有看懂 哪里重定義了,無論名字怎么修改,還是重定義。
測驗代碼如下
#include <stdio.h>
#include <Windows.h>
struct list_head {
struct list_head *next, *prev;
};
#define LIST_HEAD_INIT(name) { &(name), &(name) }
#define LIST_HEAD(name) \
struct list_head name = LIST_HEAD_INIT(name)
int main(void)
{
struct list_head my_list;
LIST_HEAD(my_list);
printf("hell world\r\n");
system("pause");
return 0;
}
uj5u.com熱心網友回復:
糊涂了,明白了。。struct list_head my_list;
LIST_HEAD(my_list);
把 LIST_HEAD 宏控展開
struct list_head my_list = LIST_HEAD_INIT(my_list)
確實是 my_list 重定義了。。哎呀呀呀 ,翻車了,這個問題竟然還想了一下午。打擾了。。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/41472.html
標籤:內核源代碼研究區
上一篇:##求助,無法正常開啟虛擬機中的Linux作業系統,一直黑屏,也不報錯,沒反應,怎么辦?
下一篇:linux 報錯 Error:Failed to download metadata for repo"AppStream"
