Reputation: 1682
struct list
{
struct list **next, **prev;
}
//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')
PS: I don't have a main
function in this file. And this has to be global.
Upvotes: 2
Views: 1565
Reputation: 43753
You need to initialize the pointer-to-struct-list variable threads
with a pointer to a struct list
. {&threads, &threads}
is not a pointer to a struct list
, but it could be a struct list
.
In order to define an actual structure instance and obtain a pointer to it, you can use a compound literal and take its address:
struct list *threads = &((struct list){&threads, &threads});
(Note: compound literals ((type){initializer})
are a C99 feature; some compilers which haven't caught up to a 13-year-old standard may reject it.)
Upvotes: 3