What is the explanation of the code?

Can someone tell me what the following code is? Is this a declaration or operation of a function? Is this really the code?

static void (*const handle_screens[NO_OF_SCREENS]) (void) = { status_screens, settings_screens, access_screens, configuration_screens, history_screens }; 
+4
source share
3 answers

its constant array of function pointers that has the signature void foo(void)

It is simple. Google sophisticated declaration for exciting.

+9
source

If all else fails and you are not 100% sure that the declaration is being declared, check the cdecl utility. This is a Linux utility, but someone also created a web interface for it on cdecl.org . Choose a random number to insert for NO_OF_SCREENS #define and you will get:

 > static void (*const handle_screens[1]) (void); declare handle_screens as static array 1 of const pointer to function (void) returning void 

Link to the result.

+6
source

There is a general rule (which I just updated) that describes how to decode declarations and definitions of C. Following the instructions on this link, your declaration: handle_screens is a static array with NO_OF_SCREENS const elements of function pointers with no arguments returning void .

This array is initialized with five functions, so I would bet that NO_OF_SCREENS is 5, personally. This means that EnabrenTane is true in saying that the function definitions are void foo(void) .

+1
source

Source: https://habr.com/ru/post/1332647/


All Articles