全局结构指针初始化 结构定义 核心c
PS:我在这个文件中没有全局结构指针初始化 结构定义 核心c,c,struct,initialization,global,C,Struct,Initialization,Global,PS:我在这个文件中没有main函数。这必须是全球性的 您需要使用指向结构列表的指针来初始化指向结构列表变量线程{&threads,&threads}不是指向结构列表的指针,但它可以是结构列表 为了定义实际结构实例并获取指向它的指针,可以使用复合文字并获取其地址: struct list *threads = &((struct list){&threads, &threads}); (注意:复合文字((type){initializer})是C99的一个特性;一些没有
main
函数。这必须是全球性的 您需要使用指向结构列表的指针来初始化指向结构列表变量线程
<代码>{&threads,&threads}
不是指向结构列表的指针,但它可以是结构列表
为了定义实际结构实例并获取指向它的指针,可以使用复合文字并获取其地址:
struct list *threads = &((struct list){&threads, &threads});
(注意:复合文字
((type){initializer})
是C99的一个特性;一些没有达到13年标准的编译器可能会拒绝它。)谢谢Kevin,还有一个问题,在结构初始化旁边,我有一些类似void*vp_threads=threads;//如果我写&threads,这很好,但是没有“&”its giving me error“初始值设定项元素不是常量”为什么?知道吗?我不知道,抱歉。当然,这是两个不同的指针。如果你在这方面需要帮助,你应该问一个单独的问题,并给出你需要完成的更多细节。
//Global struct
struct list *threads = {&threads, &threads}; //Warnings here:
// warning: initialization from incompatible pointer type
// warning: excess elements in scalar initializer
// warning: (near initialization for 'threads')
struct list *threads = &((struct list){&threads, &threads});