The standard does allow implementations to support such programs, but
does not require them to.
Oops, yes. I wrote allow instead of require!
In fact this is not an uncommon extension.
But I wasn't talking about that.
I was talking about a definition of int printf() _as provided by the
implementation_, rather than a definition of
int printf(FILE *, const char *restrict, ...). Can an implementation that
defines it as int printf() -- and does not rely on the as-if rule for
Which specific instance of the as-if rule? The as-if principle is broad.
You mean, if the implementation actually just implements printf
in the old style, using exactly the same mechanisms that are offered
to the user-defined program, and no hidden magic?
Just because old-style functions are incompatible with variadic funtions
doesn't mean that such combinations are required to fail.
In some C compilers, the calling conventions and the handling of
varaidic arguments is such that an old-style definition
can handle the variable arguments just fine.
This means that not only can an implementation define printf
using an old-style definition, but that implementation will likely
allow your own programs to get away with the same thing.
Variable-argument handling in fact grew out of the permissiveness
of old-style functions: that there was no checking on the
number of arguments passed, and the calling conventions of compilers
were such that the superfluous arguments were just ignored by the called
function. Someone hacked up a tool to get at the extra arguments
in a somewhat disciplined way, and this became <varargs.h>
Today you have to use the prototype ellipsis. This allows for
variadic functions to use special conventions. I.e. if you
have a machine with lots of registers, then a 10 argument
call might just use registers for all the arguments.
But a 10 argument call to a variadic function with only
two required arguments might use two registers for those
arguments, and put the rest into memory that can be represented
as a va_list and iterated over.
this -- meet all requirements of the standard?
Which requirements do you suspect couldn't be met if an old-style definition of
printf just worked naively?