L
luser- -droog
Hello.
I've got a function that takes a variable number of enum
values using stdarg. Right now I'm explicitly casting
the arguments to int in the call so I can peel them back
off as ints in the function and feel pretty safe about it
without poring over the standard looking for trouble.
So the question is: do enums suffer the "usual promotions"
so I can expect them to be passed as ints in a vararg
function call? I'd like to drop the casts, if possible.
They offer no 'content' to the reader.
eg.
object consoper (state *st, char *name,
void (*fp)(), int out, int n, ... /* enum typepat pat0, ... ,
patN-1 */) {
object nm;
size opcode;
int i;
....
va_list args;
/* load pattern from variable arguments */
va_start(args,n);
for (i = 0; i < n; i++) {
optab[opcode].sig[ sp ].t = va_arg(args, int);
}
va_end(args);
....
op = consoper(st, "pop", Apop, 0, 1, (int)anytype); INSTALL;
op = consoper(st, "exch", AAexch, 2, 2, (int)anytype,
(int)anytype); INSTALL;
op = consoper(st, "dup", Adup, 2, 1, (int)anytype); INSTALL;
op = consoper(st, "copy", Icopy, 0, 1, (int)integertype); INSTALL;
op = consoper(st, "index", Iindex, 1, 1, (int)integertype);
INSTALL;
I've got a function that takes a variable number of enum
values using stdarg. Right now I'm explicitly casting
the arguments to int in the call so I can peel them back
off as ints in the function and feel pretty safe about it
without poring over the standard looking for trouble.
So the question is: do enums suffer the "usual promotions"
so I can expect them to be passed as ints in a vararg
function call? I'd like to drop the casts, if possible.
They offer no 'content' to the reader.
eg.
object consoper (state *st, char *name,
void (*fp)(), int out, int n, ... /* enum typepat pat0, ... ,
patN-1 */) {
object nm;
size opcode;
int i;
....
va_list args;
/* load pattern from variable arguments */
va_start(args,n);
for (i = 0; i < n; i++) {
optab[opcode].sig[ sp ].t = va_arg(args, int);
}
va_end(args);
....
op = consoper(st, "pop", Apop, 0, 1, (int)anytype); INSTALL;
op = consoper(st, "exch", AAexch, 2, 2, (int)anytype,
(int)anytype); INSTALL;
op = consoper(st, "dup", Adup, 2, 1, (int)anytype); INSTALL;
op = consoper(st, "copy", Icopy, 0, 1, (int)integertype); INSTALL;
op = consoper(st, "index", Iindex, 1, 1, (int)integertype);
INSTALL;