Search code examples
cccminix

"Illegal use of selector" in C


As part of a larger project, I am trying to write a C function that searches an implemented sorted linked list for a value in the struct olnode. I'm receiving a few errors, however. I'm new to C and I'm struggling with pointers and double pointers and when to use what, so I think that's part of the problem, but I'm not sure how to fix the problem. All necessary headers are included. This is on Minix 2.0.4 using cc as the compiler.

I can provide any additional necessary code; as I'm unfamiliar with C I'm not sure how much I need to show so I'm providing what I think is needed and nothing more to keep it short.

Global code (other than headers):

#define POOLSZ 53
struct olnode {
    int eventnr;
    int eventfq;
    struct olnode *next;
};
typedef struct olnode olnode;
olnode pool[POOLSZ];
olnode *avail;    /* points to first available node */

Function that is returning errors (searches for the passed int, after completion *current should be the olnode that holds the current value):

void
srchfreq(olnode *list, int xfrequency, olnode **current)
{
    olnode *previous, *newnext;

    while(current->eventfq > xfrequency) {
        *previous = &current;
        *newnext = current->next;
        *current = *newnext;
    }
}

Function call of srchfreq() (in a different function):

/* *list points to the first node in the list
   (*current).eventfq is the value being searched for
*/

srchfreq(*list, (*current).eventfq, &current);

Errors (line numbers are edited to be with respect to lines in srchfreq() as given above):

line 6: illegal use of selector eventfq
line 7: cannot convert pointer to struct
line 8: illegal use of selector next
line 8: cannot convert pointer to struct
line 9: cannot convert struct to pointer

Solution

  • void
    srchfreq(olnode *list, int xfrequency, olnode **current)
    {
        olnode *previous, *newnext;
    
        while((*current)->eventfq > xfrequency) {
            previous = *current;
            newnext = (*current)->next;
            *current = newnext;
        }
    }
    

    Second part depends on types of arguments. If list declared as olnode *list, there is no need to dereference it, since function expects a pointer. Second and third arguments are wrong (one of them - to determine which one we need to know how current is declared).