I had a second question which is probably a dumb question, but here
Not a problem.
I'm just wondering how a function that has all varargs knows what to do.
I'm only familiar with the C style of varargs. In that case you
generally used one or more fixed parameters that told you how to
interpret the rest. Like the format string in printf, for example. I
suppose the function could look at a static variable somewhere to get
this data. That sounds messy. Are these functions member functions
with an implied first parameter perhaps? If so, why not explicitly?
I assume you're talking about the va_start intrinsic:
Basically here's the jist of it. At least in C, it's impossible to make
use of varargs parameters in a function with zero declared arguments,
because the va_start macro requires the last argument as the parameter.
LLVM, however, is not necessarily tied down to C (we want to support
arbitrary languages), and adding the argument to va_start just makes
things needlessly more complex (what if the argument passed in is not the
The organization we have now allows us to put the error checking code in
the front-end for languages which do not allow this. For a hypothetical
language which does allow varargs without a fixed, we support it just
Essentially, these are the three reasons we don't have a restriction:
1. There MIGHT be some language that wants support for funny stuff like
2. It's easier to build the error checking into the C front-end, and then
support the general case in LLVM.
3. Supporting the general case in LLVM is no harder than the "C" case.
Also, FWIW, it's very typical to define a varargs function with no
arguments in C. In particular this function:
Is varargs in C. Contrast this with:
And you are beginning to see a flavor of the fun stuff the C front-end has
to deal with. Of course, you can't USE the varargs in the body, so
the LLVM compiler transforms "void foo()" into "void foo(void)" when the
body is found, assuming it has no arguments.