I'm trying to figure out what the following code in C does?
((void(*)())buf)();
where 'buf' is a char array.
Let's take it one step at a time.
void(*)()
This is a pointer to a function that takes unspecified arguments and has no return value.
(void(*)())buf
simply casts buf to this function pointer type. Finally,
((void(*)())buf)();
calls this function.
So the entire statement is "interpret buf as a pointer to a void function without arguments, and call that function."
It casts buf to a function pointer of type void(*)() (A function returning nothing/void and taking unspecified arguments) and calls it.
The ANSI standard does not really allow the casting of normal data pointers to function pointers, but your platform may allow it.
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