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 to make void (**)() from void()?

Have function:

void btCallback(esp_spp_cb_event_t event, esp_spp_cb_param_t *param) { 
  // ...
}

Need to use in:

BT.register_callback(btCallback);

Compiler error:

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

no known conversion for argument 1 from 'void(esp_spp_cb_event_t, esp_spp_cb_param_t*)' to 'void (**)(esp_spp_cb_event_t, esp_spp_cb_param_t*)'

As I understand it, he needs a pointer to function pointer. I don’t know how to create it. I tried a function pointer (through &), does not fit.

P.S. Is arduino-esp32 BluetoothSerial::register_callback function.

>Solution :

You need to make a pointer variable, and then take a pointer from it using the & operator.

void f()
{
    // ...
}

void g(void (**p)())
{
    // ...
}

int main()
{
    void (*f_ptr)() = f;
    g(&f_ptr);
}

Try if here.

As I understand it, he needs a pointer to function pointer. I don’t
know how to create it. I tried a function pointer (through &), does
not fit.

In the previous example, taking &f doesn’t have any effect. These two lines are equivalent!:

void (*f_ptr)() = f;
void (*f_ptr)() = &f;

Therefore, if you were doing:

g(&f);

you are actually passing a simple function pointer, not a pointer to function pointer.

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