1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
#include <interface99.h>
#include <assert.h>
#define TestDefault_IFACE vfuncDefault(void, default_op, VSelf, int x)
interface(TestDefault);
static void TestDefault_default_op(VSelf, int x) {
VSELF(void);
(void)self;
(void)x;
}
static void custom_impl(VSelf, int x) {
VSELF(void);
(void)self;
(void)x;
}
typedef struct {
char dummy;
} A;
impl(TestDefault, A);
typedef struct {
char dummy;
} B;
#define B_default_op_CUSTOM ()
#define B_default_op custom_impl
impl(TestDefault, B);
#define TestNoOpCustom_IFACE vfunc(void, custom_op, VSelf, int x)
interface(TestNoOpCustom);
typedef struct {
char dummy;
} C;
// This `*_CUSTOM` attribute must be no-op.
#define C_custom_op_CUSTOM ()
#define C_custom_op custom_impl
impl(TestNoOpCustom, C);
int main(void) {
assert(VTABLE(A, TestDefault).default_op == TestDefault_default_op);
assert(VTABLE(B, TestDefault).default_op == custom_impl);
assert(VTABLE(C, TestNoOpCustom).custom_op == custom_impl);
return 0;
}
|