6

here is the code:

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

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

For that last line, i get the error message: "Expected ')' before '*' token"

why?

4 Answers 4

5

You have the correct way of doing a function pointer in your struct (so kudos for that, so many people get it wrong).

Yet you've swapped around the drawFunc and * in your function definition, which is one reason why the compiler is complaining. The other reason is that you have the same identifier being used as the type and the variable. You should choose different identifiers for the two different things.

Use this instead:

void glesRegisterDrawFunction(glesContext *cntxt, void(*drawFunc)(glesContext*));
                                                       ^^^^^^^^^
                                                       note here
Sign up to request clarification or add additional context in comments.

Comments

5

One solution is to add a pointer to function typedef 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);

1 Comment

Typedeffing function pointers can make them easier to deal with.
0

You might want to try putting this in parentheses: glesContext *glesContext.

Comments

0

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.