Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error: expected primary-expression before ')' token (C)

Tags:

I am trying to call a function named characterSelection(SDL_Surface *screen, struct SelectionneNonSelectionne sel) which returns a void

This is the .h of the function I try to call:

struct SelectionneNonSelectionne;
void characterSelection(SDL_Surface *screen, struct SelectionneNonSelectionne);
void resetSelection(SDL_Surface *screen, struct SelectionneNonSelectionne);

On my main function, I try to call it like this:

characterSelection(screen, SelectionneNonSelectionne);

When I compile, I have the message:

 error: expected primary-expression before ')' token

I made the includes. I suppose I miscall the second argument, my struct. But, I can't find why on the net.

Have you got any idea about what I did wrong?

like image 502
Flo Avatar asked Feb 01 '15 11:02

Flo


2 Answers

You should create a variable of the type SelectionneNonSelectionne.

struct SelectionneNonSelectionne var;

After that pass that variable to the function like

characterSelection(screen, var);

The error is caused since you are passing the type name SelectionneNonSelectionne

like image 168
ninja Avatar answered Sep 24 '22 08:09

ninja


A function call needs to be performed with objects. You are doing the equivalent of this:

// function declaration/definition
void foo(int) {}

// function call
foo(int); // wat!??

i.e. passing a type where an object is required. This makes no sense in C or C++. You need to be doing

int i = 42;
foo(i);

or

foo(42);
like image 39
juanchopanza Avatar answered Sep 24 '22 08:09

juanchopanza