() obsoleted?!

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);
}
}
 
P

Peter Nilsson

Arthur said:
How does C++ handle 'int bar(...)', if the 'va_start'
interface is the same as in C?

It doesn't. That is, you can't access the parameters using <stdarg.h>
for a function prototyped as (...). All you can portably do is ignore
them.
I assume you're not just talking about overloading
and default parameter values, but actually variadic functions
using the '...' syntax.

C++'s <stdarg.h> is limited to variadic functions with at least one
parameter. Which makes Chris Torek's reply all the more intreging!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,161
Messages
2,570,892
Members
47,427
Latest member
HildredDic

Latest Threads

Top