va_args going unused ok?

M

Michael B Allen

Is it legit to not use arguments of a variable argument function? For
example consider that printf here does not use arg if fi = 1.

void
foo(int fi, const char *arg)
{
const char *fmts = { "%s", "" };
printf(fmts[fi], arg);
}

Thanks,
Mike
 
K

Krishanu Debnath

Michael said:
Is it legit to not use arguments of a variable argument function? For
example consider that printf here does not use arg if fi = 1.

void
foo(int fi, const char *arg)
{
const char *fmts = { "%s", "" };
typo I guess, you meant ..
const char *fmts[] = { "%s", "" };
printf(fmts[fi], arg);
}

Thanks,
Mike
Yes, it is legitimate. c99 Sec 7.19.6.1 para 2 says ..
"If the format is exhausted while arguments remain, the excess arguments
are evaluated (as always) but are otherwise ignored."

Krishanu
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top