Is something like 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();
}
//see "hello world" on stdout
In short, I'd like to have a function pointer that "stores" the arguments. The point is that the function pointer can be used later on without needing a reference to the original data.
I could use something like this to couple 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 wouldn't be as elegant as just calling a function pointer with the argument inside.