Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I correctly assign a pointer to a call back function?

I try to call a function in a IRQ with C, with the next code I get it.

static void (*functionPulsacion)();

void eint2_init(void *funcPulsacion){
    functionPulsacion = funcPulsacion;
}

But when I compile in Keil the IDE show me the next message:

Button2.c(38): warning: #513-D: a value of type "void " cannot be assigned to an entity of type "void ()()"

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

What is the good way for do this?.

Thank you in advance

>Solution :

It’s the same syntax for the parameter variable as for the static one.

static void (*functionPulsacion)(void);

void eint2_init(void (*funcPulsacion)(void)) {
    functionPulsacion = funcPulsacion;
}

Typedefs make function pointers a lot more readable, though.

typedef void (*PulsacionFunc)(void);

static PulsacionFunc pulsacion_func;

void eint2_init(PulsacionFunc a_pulsacion_func) {
   pulsacion_func = a_pulsacion_func;
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading