Is void *function() a pointer to function or a function returning a void*?
The function has the return type
So I always prefer in such cases to separate the symbol
* from the function name like
void * function();
Jarod42 pointed to in a comment you can rewrite the function declaration in C++ using the trailing return type like
auto function() -> void *;
If you want to declare a pointer to function then you should write
void ( *function )();
where the return type is
void * ( *function )();
where the return type
Or a pointer to function that returns pointer to function
void * ( *( *function )() )();
It is a function returning a pointer to
Think of your declaration this way:
This would be a function returning
void (or nothing):
Think of the above declaration this way:
A much easier way to write these is to use
typedef void *function_returning_void_pointer(); typedef void function_returning_nothing(); function_returning_void_pointer function; function_returning_nothing *function2;
This generally eliminates the confusion around function pointers and is much easier to read.
Whenever I'm unsure about C syntax issues, I like to use the cdecl utility (online version) to interpret for me. It translates between C syntax and English.
For example, I input your example of
void *foo() and it returned
declare foo as function returning pointer to void
To see what the other syntax would look like, I input
declare foo as pointer to function returning void and it returned
This gets particularly useful when you have multiple levels of typecasts, stars, or brackets in a single expression.