Pages: [1]   Go Down
Author Topic: void and (void) in function declaration  (Read 260 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: 82
Posts: 3123
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: 239
Posts: 24373
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
Online Online
Faraday Member
**
Karma: 49
Posts: 3422
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: 92
Posts: 3969
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

Why not visit my eBay shop? http://stores.ebay.co.uk/Majenko-Technologies
Replacement for the Arduino IDE: UECIDE - Proper serial terminal, graphing facilities, plugins, overhauled internals.
Java isn't bad in itself, but it has enabled morons to write programs.

Pages: [1]   Go Up
Jump to: