What does this line do in C?
 int (*func)();
I extracted it from the following program that is supposed to execute byte code (assembly instructions converted to its corresponding bytes)
char code[] = "bytecode will go here!";
int main(int argc, char **argv)
{
  int (*func)();
  func = (int (*)()) code;
  (int)(*func)();
}
                The line in question declares a function pointer for a function with unspecified arguments (an "obsolescent" feature since C99) and with return type int.
The first line of your main declares that pointer, the second line initializes the pointer so it points to the function code. The third line executes it.
You can get a description of pointers to functions in general here.
int (*func)(); declares func as a pointer to a function that returns an int type and expects any number of arguments.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With