Reputation: 10153
How I make the following code work? I want to print "non defined" instead of -1.#IND00
int myprint(const char* format, ...)
{
va_list args;
va_start (args, format);
int ret;
if(_isnan(static_cast<float>(*args)))
ret = printf ("non defined");
else
ret = vprintf (format, args);
fflush(stdout);
va_end (args);
return ret;
}
int main()
{
myprint("%f", sqrt(-1.0));
return 0;
}
Upvotes: 3
Views: 1693
Reputation: 206689
You can't use args
like that, you have to use va_arg
to get an actual argument.
if(_isnan(va_arg(args,double)))
would do the trick, but that won't help you much. You can't infer the type from the arguments. The type you indicate to va_arg
must be the actual type of the object passed in.
And with that, your vprintf
call won't work either, you need to "re-start" the va_list since va_arg
has "consumed" one argument already.
Upvotes: 3