简体   繁体   中英

What's the meaning of this declaration?

I saw this one in one of the .h files provided by my professor for a project, but I'm not too sure what this means.

int (*get_console_dev)(void);

Is it the same as

(int*) get_console_dev(void);

(a function named get_console_dev, which returns a pointer to an int ?)

Thanks

It's a function pointer that can point to a function returning int and taking 0 parameters; it's not equivalent to the second line you posted.

int (*get_console_dev)(void) is a function pointer declaration. get_console_dev is a variable that can hold a reference to a function matching the specific signature.

int consoleFunction(void);

// ...

int (*get_console_dev)(void);

get_console_dev = consoleFunction;

This declaration is not the same as: (int*) get_console_dev(void); .

Check this with cdecl .

int (*get_console_dev)(void);

This is Pointer pointer function with no parameter and return type as integer.

(int*) get_console_dev(void);

This is function with no parameter and return type as pointer of type integer.

Both are completely different.

Please read up function pointers. it is a pointer to a function that takes void (as argument) and returns integer

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM