Expected ')' before the token '*' with a function pointer

here is the code:

typedef struct { void (*drawFunc) ( void* ); } glesContext; void glesRegisterDrawFunction(glesContext *glesContext, void(drawFunc*)(glesContext*)); 

For this last line, I get the error message: "Expected") "before the token" * "

why?

+6
source share
4 answers

You have the right way to make a pointer to a function in a struct (so that’s enough for this, so many people are wrong).

However, you swapped drawFunc and * in the definition of your function, which is one of the reasons the compiler complains. Another reason is that you have the same identifier, which is used as a type and a variable. You have to choose different identifiers for two different things.

Use this instead:

 void glesRegisterDrawFunction(glesContext *cntxt, void(*drawFunc)(glesContext*)); ^^^^^^^^^ note here 
+5
source

One solution is to add a pointer to the typedef function as follows:

 typedef struct { void (*drawFunc) ( void* ); } glesContext; // define a pointer to function typedef typedef void (*DRAW_FUNC)(glesContext*); // now use this typedef to create the function declaration void glesRegisterDrawFunction(glesContext *glesContext, DRAW_FUNC func); 
+5
source

You might want to put this in parentheses: glesContext * glesContext.

0
source

I'm not quite sure what your code is trying to do, but if you just want to compile it, try

 void glesRegisterDrawFunction(glesContext *glesContext, void (*drawFunc)(glesContext*)); 
0
source

Source: https://habr.com/ru/post/908864/


All Articles