Jay
Jay

Reputation: 5

C: linked lists confusion

error: dereferencing pointer to incomplete type
The problem line is "gl->point[0] = (struct list *)&foo;"
I read somewhere that I could be storing a declaration. If that is the case I need that explained to me.

struct ref {  
    char **name;
    struct list **point;
};

int main ( ) {   
    typedef struct {
        char **name;
        struct list **point;
    } temp;  

    struct ref *gl;  

    gl->name = malloc ( 1024 * sizeof(char *) );  
    gl->name[0] = "A";  

    temp foo;  
    foo.name = malloc ( 1024 * sizeof(char *) );  
    foo.name[0] = "B";  

    gl->point[0] = (struct list *)&foo;   

    printf ( "!%s!\n" , gl->point[0]->name[0] );  
}

Upvotes: 0

Views: 91

Answers (2)

Richard Harrison
Richard Harrison

Reputation: 19393

Nowhere in the code sample are you defining struct list which is what the error is.

Upvotes: 0

Pablo Santa Cruz
Pablo Santa Cruz

Reputation: 181280

What's struct list? There is no type named struct list (at least in what you've shown).

Maybe you meant struct ref?

Upvotes: 1

Related Questions