This is the cutest syntax I've used with variable macros (C99):
#define call(obj, method, ...) ((obj).method(&(obj), __VA_ARGS__))
usage (click for ideone) :
struct class { int a; int (*method)(struct class* this, int b, int c); }; int code(struct class* this, int b, int c) { return this->a*b+c; } struct class constructor(int a) { struct class result = {a, code}; return result; } #define call(obj, method, ...) ((obj).method(&(obj), __VA_ARGS__)) #include <stdio.h> int main() { struct class obj = constructor(10); int result = call(obj, method, 2, 3); printf("%d\n", result); return 0; }
source share