Reputation: 1651
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)();
}
Upvotes: 5
Views: 7243
Reputation: 2982
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.
Upvotes: 5
Reputation: 106012
int (*func)();
declares func
as a pointer to a function that returns an int
type and expects any number of arguments.
Upvotes: 3