2012-04-23 43 views
2

我一直是這樣的:全球無效*,使其指向結構的指針

struct list{ 
    struct list **next, **prev; 
} 

全局聲明:

struct list *threads = &((struct list){&threads, &threads}); 
void* vp_threads;  /Error here: previous declaration of 'vp_threads' was here 
vp_threads = threads; //Error here: conflicting types for vp_threads 

第二個方法我試過:

void* vp_threads = threads; //Error: initializer element is not constant 

我有這樣做是因爲...(見下文!)

void some_func() 
{ 
    add_head(vp_threads, ...) 
... 
} 

void add_head(void* x, ...) 
{ ... } 

(PS:還有不是主()或初始化函數,這是core.c文件類型,實現所有這一切都在.H功能)

爲什麼這不工作,我只是想使void *指向我的結構。這有什麼問題?

回答

1

嘗試做

vp_threads = threads; 

(或初始化函數)

你不能把一個聲明在全局範圍內。你的聲明vp_threads = threads;將不得不生活在某個功能

+0

我試過了,它給了我錯誤「初始化元素不是常量」 – 2012-04-23 22:03:17

+0

更新了答案 – 2012-04-23 22:21:51

+0

以及這個core.c文件,只是函數的實現。沒有主要的或任何初始化函數,這就是爲什麼我想要全局。 我應該告訴在 – 2012-04-23 22:56:27