In C, does * also mean the same as void when used as a function argument?

For example, view the following (abstract) ad:

int (*) (*) 

// pointer to a function that returns int and does not accept arguments

(which I received from the following site: http://www.vineetgupta.com/blog/deciphering-complex-c-declarations )

I thought that only void means no arguments. It really means the same as:

 int (*) (void) 

If so, where does it indicate that * can be used to indicate arguments?

Also, can I suggest that abstract declarations like this exist only for type casting? If so, then it must be invalid in its current form, since it does not have the right environment. So int(*)(void) is invalid, but (int(*)(void)) valid, no?

+4
source share
2 answers

pointer to a function that returns int and does not accept arguments

This is not so - the function takes a pointer as its argument, but since there is no type specifier, the base type of the pointer is considered int . This is an ancient (pre-standard) behavior, some compilers allow this, others do not.

I thought that only void means no arguments. It really means the same as:

 int (*) (void) 

No, this is not due to the reason described above.

Also, can I proceed from the assumption that abstract declarations such as this exist only for customization of types?

No, they can also be used in function argument lists in function declarations. In this way,

 int factorial(int); 

excellent so

 void qsort(void *, size_t, size_t, int (*)(const void *, const void *)); 
+13
source

EDIT

  int (*) (*) 

results in an error when I try in visual studio, and this is not a way of declaring.

If you want the function pointer to return integer data with the pointer as an argument, the correct way to do this is below.

  int(*foo)(datatype *). 

where the data type may be

  int ,float,char etc 

and void and * do not match.

0
source

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


All Articles