M
marcus hall
Not exactly what I'm having in mind. I had the situation like this (when
writing a language interpreter).
void interpret(void)
{
void (*op)();
while(1) {
/* fetch opcode and initialize op based on it */
op(arg1, arg2, ...);
}
}
Then each of the called-by-op functions had their real definition like:
void op1(int);
void op2(int, int);
void op3(int, double);
etc.
the interpreter loop is always calling via the pointer with correct number and
types of arguments.
In this case I didn't have to mess around with va_ macros, and everything
was 'cleaner'... Now the () feature is obsoleted in C99 with nothing to
replace it in future version of the standard...
You could always create a union for op:
union interp_fcn {
void i(int);
void ii(int);
void id(int, double);
};
void interpret(void)
{
union interp_fcn *op;
while(1) {
/* fetch opcode and initialize op based on it */
op->ii(arg1, arg2);
}
}