I'm learning C programming and facing a problem. I would like to "extract" a long double from a list of arguments. But, when I ask va_arg to "catch" a long double argument, I have a random error (as it is mentionned in the man about bad va_arg calls). But how would it be possible for me to solve this problem? Here is an example of code illustrating the pb:
void func(va_list *ptr)
{
long double f;
f = va_arg(*ptr, long double);
printf("Value extracted: %Lf\n", f);
return ;
}
void func2(char *format, ...)
{
va_list ap;
va_start(ap, format);
func(&ap);
va_end(ap);
return ;
}
Thanks for your help!
Edit: I know how to use va_arg (at least for simple stuff). As you can see, the function takes a pointer to a va_list as argument. This is because I call va_start in the calling function (and va_end at the end of the same calling function). I just wanted to show you the problem and nothing else.
I have no problem with other data types (int, long, char, char *, etc.). It's just a long double pb.
Edit #2: I wrote a calling function to show you I am not forgetting va_start and va_end. And, to conclude, my problem is that I am trying to code my own printf function and I am dealing with the -Lf conversion. I didn't think it would be necessary to mention it, sorry about this.