Is this possible in C?
#include <stdio.h>
void print_str(char *str) {
printf(str);
}
int main() {
void (*f_ptr)() = print_str,"hello world";
f_ptr();
}
In short, I would like to have a pointer to a function that “stores” the arguments. The fact is that a function pointer can be used later without requiring a reference to the source data.
I could use something like this to bind a function pointer and an argument reference
struct f_ptr {
void (*f)();
void *data;
}
void exec_f_ptr(f_ptr *data) {
data->f(data->data):
}
but it won't be as elegant as just calling a function pointer with an argument inside.
source
share