Skip to main content
Code edits, don't hide pointer
Source Link
unwind
  • 401.8k
  • 64
  • 492
  • 620

In situations like this, do a typedef to name your function pointersignature, that makes it far simpler.:

typedef void (*MESSAGE_HANDLER)MESSAGE_HANDLER(void); 

with that in place, it should be just:

const MESSAGE_HANDLER * const handlers[] = { function1, function2 }; 

To get the actual content of the array constant.

EDIT: Removed pointer part from the typedef, this really is better (live and learn).

In situations like this, do a typedef to name your function pointer, that makes it far simpler.

typedef void (*MESSAGE_HANDLER)(void); 

with that in place, it should be just:

const MESSAGE_HANDLER handlers[] = { function1, function2 }; 

To get the actual content of the array constant.

In situations like this, do a typedef to name your function signature, that makes it far simpler:

typedef void MESSAGE_HANDLER(void); 

with that in place, it should be just:

MESSAGE_HANDLER * const handlers[] = { function1, function2 }; 

To get the actual content of the array constant.

EDIT: Removed pointer part from the typedef, this really is better (live and learn).

Source Link
unwind
  • 401.8k
  • 64
  • 492
  • 620

In situations like this, do a typedef to name your function pointer, that makes it far simpler.

typedef void (*MESSAGE_HANDLER)(void); 

with that in place, it should be just:

const MESSAGE_HANDLER handlers[] = { function1, function2 }; 

To get the actual content of the array constant.