Go Down

Topic: void and (void) in function declaration (Read 392 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?

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy