【问题标题】:Global void*, making it pointer to structure pointer全局 void*,使其指向结构指针
【发布时间】:2012-04-23 21:39:29
【问题描述】:

我有类似的东西:

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:没有main()或初始化函数,这是core.c文件的那种,实现了.h中的所有函数)

为什么这不起作用,我只是想让 void* 指向我的结构。这是怎么回事?

【问题讨论】:

    标签: pointers void


    【解决方案1】:

    尝试做

    vp_threads = threads;
    

    在main(或初始化函数)中

    您不能将语句放在全局范围内。您的声明 vp_threads = threads; 必须存在于某个函数中

    【讨论】:

    • 我试过了,它给了我错误“初始化元素不是恒定的”
    • 这是core.c文件,只是功能的实现。没有主函数或任何初始化函数,这就是我想要全局的原因。我应该在问题中告诉
    • 有一个名为 core_init() 的函数并调用它
    • 不能这样做......这被同一文件中的其他函数使用......!
    • 没关系,初始化后一切都可以使用了
    猜你喜欢
    • 2016-03-21
    • 2014-10-01
    • 1970-01-01
    • 2012-07-23
    • 2012-03-15
    • 1970-01-01
    • 1970-01-01
    • 2015-01-04
    • 1970-01-01
    相关资源
    最近更新 更多