H
Harald van Dijk
Hello all,
Is it possible to know what an enumeration type promotes to? Given this
code,
#include <stdio.h>
#include <stdarg.h>
enum EnumerationType
{
Value1,
Value2,
Value3
};
void VarArgFunc(int dummy, ...)
{
va_list ap;
va_start(ap, dummy);
printf("VarArgFunc called with dummy=%d, ...=", dummy);
switch (va_arg(ap, /* ??? */))
{
case Value1: puts("Value1"); break;
case Value2: puts("Value2"); break;
case Value3: puts("Value3"); break;
}
va_end(ap);
}
int main(void)
{
enum EnumerationType variable = Value1;
VarArgFunc(0, variable);
}
what's the right type to pass to va_arg? I've been looking at code that
does just this, using va_arg(ap, enum EnumerationType), which fails
horribly at runtime when compiled on systems where enum EnumerationType
turns out to be compatible with unsigned char. What's the right way of
dealing with this? Will an enumeration type always promote to signed or
unsigned int, or can it also promote to something larger (both in theory
and in practise)?
Is it possible to know what an enumeration type promotes to? Given this
code,
#include <stdio.h>
#include <stdarg.h>
enum EnumerationType
{
Value1,
Value2,
Value3
};
void VarArgFunc(int dummy, ...)
{
va_list ap;
va_start(ap, dummy);
printf("VarArgFunc called with dummy=%d, ...=", dummy);
switch (va_arg(ap, /* ??? */))
{
case Value1: puts("Value1"); break;
case Value2: puts("Value2"); break;
case Value3: puts("Value3"); break;
}
va_end(ap);
}
int main(void)
{
enum EnumerationType variable = Value1;
VarArgFunc(0, variable);
}
what's the right type to pass to va_arg? I've been looking at code that
does just this, using va_arg(ap, enum EnumerationType), which fails
horribly at runtime when compiled on systems where enum EnumerationType
turns out to be compatible with unsigned char. What's the right way of
dealing with this? Will an enumeration type always promote to signed or
unsigned int, or can it also promote to something larger (both in theory
and in practise)?