In my main
function, I use the following code
float f = 32.0;
func("test string %f", f);
func
(these are all example names) is declared as following
void func(const char *str, ...);
In my implementation of this function, I use a union called all_types
to obtain the value of the arguments that are passed
union all_types
{
void *v;
CLObject *obj;
char *s;
long l;
char c;
float f;
int i;
double d;
};
and then give a value to that union like this
union all_types *o = calloc(1, sizeof(union all_types));
while ((o->v = va_arg(list, void *)) != NULL)
Now, when I know the argument is a float, the value for it will be very strange (I set a breakpoint to figure it out). The i
and l
values on the union will be 32, as they should. However, the f
value is some weird number like 0.00000000000000000000000000000000000000000013592595
. Does anyone know why I am getting this behavior? This function works for every other type of object I have tested.