Eric Sosman said:
The fundamental problem is that C is a statically-typed
language, meaning that the type of every expression is fixed
at compile time. True, <stdarg.h> (not <varargs.h>, BTW) can
evade this requirement, but only briefly: In order to access
the arguments corresponding to `...', you must use an expression
whose type is known and immutable. C is not Lisp.
Funny you should mention that - and in just that way.
<rant>
WARNING WARNING WARNING - OFF TOPIC OFF TOPIC OFF TOPIC (*)
</rant>
If you google to the right place, you'll find the following text posted by
one K. McCormack at some point in the not so distant past:
<text from google>
The answer is a neat little package called "ffcall", which came out of the
Common Lisp effort, and allows you to setup calls to variadic functions at
something like the assembler level - you basically are pushing args onto
the stack, in a loop. The ffcall package contains 4 related things - the
only one you need for my version of strfmon() is the "avcall" package.
You can get ffcall from: ftp://ftp.santafe.edu/pub/gnu/ffcall-1.6.tar.gz
</text from google>
Note that ffcall is described as "var args in reverse", but I think of it
as "var args at runtime". Note that var args is all compile-time.
The point is that *it* *allows* you to write a C program that works like
this:
:loop
Enter a type and a value...
goto :loop
After exiting loop (running the loop an arbitrary number of times), call
printf, and print out all the values with the right types. That's
something you can't do with var args.
(*) Although, as an aside, is it really OT (and thus an unforgivable sin)
to state that "X can't be done in Standard C, but here's a pointer
a library (or similar external facility) that allows you to do what you
want" ?