What is the difference between int (*cmp)(void) and int *cmp(void)?

Viewed 113

What is the difference between

extern int (*func)(void);

and

extern int *func(void);

Thanks

3 Answers
extern int (*func)(void);

declares func as a pointer to a function which takes no arguments and returns an int value.

extern int *func(void);

is a forward declaration (a.k.a. a protptype) of func as a function that takes no arguments and returns a pointer to an int.

The first declares a variable, the second declares a function.

If you declare a type fp as pointer to a function, that the compiler will interpret fp() as dereferencing fp to get the address of the function.

Whereas, if fp is declared as the function itself, then any fp() in your file, will be interpret by the compiler as a near-call to the address of fp.

Meaning, that the linker will fix up the jump as the offset between the caller address, and the address of fp itself.

Not the address located at fp, but the offset to fp.

Related