Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does (int (*)()) mean in a function call

Tags:

c

Like the title says, I want to know what "(int (*)())" in a C-define-function-call means?

As example, it looks similar to this:

#define Bla(x)    (Char *) read((char *(*)()) Blub, (char **) x)

or this

#define XXX(nx, id)     PEM_ASN1_write_bio((int (*)()) id, (char *) nx)

Thank you in advance!

like image 808
pyle Avatar asked Jun 25 '26 23:06

pyle


2 Answers

The casts the argument to a pointer to a function that returns char * and takes zero or more arguments. The second function returns int.

You can use a program (and website, now) called "cdecl" to help with these, it says:

  • (char *(*)()): cast unknown_name into pointer to function returning pointer to char
  • (int (*)()): cast unknown_name into pointer to function returning int
like image 176
unwind Avatar answered Jun 27 '26 11:06

unwind


The easiest way of deciphering complex C expressions is to start with the innermost expression, then in an anti-clockwise pattern move on to the next. (int (*)())

  1. (*) A Pointer, anti-clockwise motion hits on (, then move on again to hit on )
  2. (*)() A pointer to function, move on to (, then move on again to )
  3. int (*)() A pointer to a function returning int, move on to int, then move on to hit on )
  4. (int (*)()) finally move on to (, and there you have it,

A pointer to a function returning int, since it is wrapped in the outer () is because of the macro.

Hope this helps, Best regards, Tom

like image 38
t0mm13b Avatar answered Jun 27 '26 11:06

t0mm13b