Go Down

Topic: void and (void) in function declaration (Read 341 times) previous topic - next topic

OptoLcd

Hello,

From a previous topic http://arduino.cc/forum/index.php/topic,66401.0.html
I came across the code segment below and the (void) has stumped me.

I would be grateful if someone would explain the function since I only know the single void declaration.
Thanks in advance.

Code: [Select]
void (*menu_funcs[NUM_MENU_ITEM])(void) = {

  condition,
  lager,
  ale,
  strike,
  boil

};

Arrch

It's not a function, It's an array of function pointers. So something like this:

Code: [Select]
menu_funcs[1]();

Would be the same as this

Code: [Select]
lager();

AWOL

...and the second void specifies the function takes no arguments.
A bit like me, really.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

wildbill

Pointers to functions allow you do some powerful stuff with the opportunity to make your code compact. I've rarely seen them used with the arduino, so you could easily forget what you just saw if it suits you. On the other hand, it's a useful technique to have in your toolbox.

OptoLcd

Thanks all.

"pointers to functions" was the key phrase for Google.

majenko


...and the second void specifies the function takes no arguments.
A bit like me, really.

You're void?
Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

Go Up