Do you consider (ab) using a preprocessor?
#include <stdio.h>
#define wrapper(f) \
f; \
void foo(int x, int y) {
printf("x: %d; y: %d\n", x, y);
}
void bar(char *str) {
printf("str: %s\n", str);
}
int main(void) {
wrapper(foo(42, 11));
wrapper(bar("hello world"));
}
, ab- (ab), , , , populus. , , , , , . , , , .
, " Javascript, , , Javascript...".
, , , , , C... , .
, Javascript .
#include <stdio.h>
struct argument;
typedef struct argument argument;
typedef void function(argument *);
struct argument {
function *function;
int x;
int y;
char *str;
};
void wrapper(argument *a) {
a->function(a);
}
void foo(argument *a) {
printf("x: %d; y: %d\n", a->x, a->y);
}
void bar(argument *a) {
printf("str: %s\n", a->str);
}
#define foo(...) wrapper(&(argument){ .function = foo, __VA_ARGS__ })
#define bar(...) wrapper(&(argument){ .function = bar, .str = "", __VA_ARGS__ })
int main(void) {
foo(.x = 42, .y = 11);
bar(.str = "hello world");
}
:
- , - , ,
printf scanf, , / . : - ,
foo bar. str "" ( ) bar. wrapper, ( , Javascript). , , wrapper ? .- , , .
, , foo, bar , . , , , , , - .
- default_foo default_bar - ...
, , ... , , ( ), .