0

I get this error when trying to compile: `error: invalid use of void expression

I get this error at the penultimate line: queueDump(f, q, printToken(f, e)); and I don't understand why. I'm trying to code the function printToken that prints the token pointed by e

void queueDump(FILE *f, Queue *q, void(*dumpfunction)(FILE *f, void *e)) {
    fprintf(f, "(%d) --  ", q->size);
    for (InternalQueue *c=q->head; c != NULL; c = c->next)
        dumpfunction(f, c->value);
}

void printToken(FILE *f, void *e) {
    Queue *q;
    if (!f) {
        printf("Erreur d'ouverture du fichier\n");
        exit(1);
    }
    fprintf(f, "Infix : ");
    queueDump(f, q, printToken(f, e));
    fclose(f);
}
Tomás
  • 71
  • 3
  • 14
  • `printToken(f, e)` calls `printToken` and so returns `void`, it doesn't pass the function with the variables you've given it somehow "bound" as arguments. – hnefatl Mar 25 '18 at 11:23

1 Answers1

0

Your queueDump function expects a pointer to a function while you pass the result of the execution to it.

printToken(f, e) executes function printToken with parameters f and e. Instead of this you should pass 3 parameters to queueDump - printToken, f, e; queueDump will use these parameters to perform the actual execution.

(in your specific case FILE *f and c->value are used as parameters to prinToken so no need to pass additional params)

SomeWittyUsername
  • 17,203
  • 3
  • 34
  • 78