What is the difference between
extern int (*func)(void);
and
extern int *func(void);
Thanks
What is the difference between
extern int (*func)(void);
and
extern int *func(void);
Thanks
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.
difference between
int (*cmp)(void)andint *cmp(void)?
Use C gibberish ↔ English 1
Pointer Declaration
extern int (*cmp)(void); is a extern pointer to function (void) returning int.
Function Declaration
extern int *cmp(void); is a extern function (void) returning pointer to int.
1 "func" is a keyword there, use `"cmp".
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.