Pages: [1]   Go Down
Author Topic: void and (void) in function declaration  (Read 311 times)
0 Members and 1 Guest are viewing this topic.
London
Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
void (*menu_funcs[NUM_MENU_ITEM])(void) = {

  condition,
  lager,
  ale,
  strike,
  boil

};
Logged

California
Offline Offline
Faraday Member
**
Karma: 91
Posts: 3427
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
menu_funcs[1]();

Would be the same as this

Code:
lager();
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 308
Posts: 26472
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

"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.

New Jersey
Offline Offline
Faraday Member
**
Karma: 70
Posts: 3726
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

London
Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks all.

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

UK
Offline Offline
Faraday Member
**
Karma: 100
Posts: 4153
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

...and the second void specifies the function takes no arguments.
A bit like me, really.
You're void?
Logged

Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

Pages: [1]   Go Up
Jump to: