Was trying to assign a function pointer to a struct member and am getting compile errors. The .h file I have to use has defined the struct:

typedef void(*callback)(bool, char*, int, unsigned long, void *);

struct CallbackInfo
    callback func;                 
    void*    stuff;

What I have in my C++ file is:

static void foo(bool val, char* a, int b, unsigned long c, void * stuff)

int funXYZ ()
 CallbackInfo callbackInfo;
 callbackInfo.func = foo; // compiler error right here
 callbackInfo.stuff= NULL;

The error I get is:

value of type "void (*)(bool, char*, int, unsigned long, void *)"
          cannot be assigned to an entity of type "callback"
              > callbackInfo.func = foo;

Any help is greatly appreciated.
Thank you.

7 Years
Discussion Span
Last Post by amare_de

This is very strange....Using the information that you have provided here I have created a working solution; no compilation errors at all (g++ compiler). Do you return from foo?
What compiler are you using?


It is a bit strange! Will it matter if the header file is wrapped around:

extern "C"

Am using GreenHills compiler (Multi). There's no return from "foo" as it has a void return type.

Edited by amare_de: missed a question.


ok.. was pointing to an older version of the .h file which caused this problem. But thank-you very much for your time to verify that the C++ code was ok.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.