Reputation: 77
Could anybody tell me what is the following code? Is it function declaration or statement? Is it valid code?
static void (*const handle_screens[NO_OF_SCREENS]) (void) =
{ status_screens, settings_screens, access_screens, configuration_screens,
history_screens };
Upvotes: 4
Views: 168
Reputation: 4879
When all else fails, and you're not 100% sure what a declaration is declaring, check out the cdecl
utility. It's a Linux utility, but somebody's also created a web interface for it at cdecl.org. Pick a random number to insert for the NO_OF_SCREENS
#define and you get:
> static void (*const handle_screens[1]) (void);
declare handle_screens as static array 1 of const pointer to function (void) returning void
Upvotes: 6
Reputation: 36107
There's a common rule (which I just refreshed my memory on) covering how to decode C declarations and definitions. Following the instructions on that link your declaration is: handle_screens
is a static array with NO_OF_SCREENS
entries of const
pointers to functions without arguments returning void
.
This array is being initialized with five functions so I'd bet that NO_OF_SCREENS is 5, personally. This means that EnabrenTane is correct in saying that the function definitions are void foo(void)
.
Upvotes: 1
Reputation: 7466
its a constant array of function pointers that of signature void foo(void)
Those are the easy ones. Google C Complex Declaration for the exciting ones.
Upvotes: 9