Pointing dereference inside a struct error

jelipito picture jelipito · Feb 8, 2013 · Viewed 10k times · Source

i have a function to create a circular list, i am having issues compiling, not sure if it is syntax, appreciate if someone can help.

    void CreateCircularList(struct node** listRef, struct node** tailRef)

    {    
    Push(&*listRef, "String 1");
    *tailRef=*listRef;
    Push(&*listRef, "String 2");
    Push(&*listRef, "String 3");
    Push(&*listRef, "String 4");

    *(tailRef->next)=*listRef;

    } 

the compiler flags an error in the last line:

"Member reference base type 'struct node*' is not a structure or union"

Any ideas why ? thanks

Answer

Basile Starynkevitch picture Basile Starynkevitch · Feb 8, 2013

You probably want

  (*tailRef)->next = *listRef;

as the last assignment.

You cannot write tailRef->next since tailRef is a pointer to a pointer.

I also suggest just coding Push(listRef, "Some string"); instead of your Push(&*listRef, "Some string"); for readability reasons.