3 ms·
> The C vararg spec is not well-designed. If you pass all function arguments via the stack, va_start may be implemented pretty easily, but on the modern process
by kazinator 7y ago
> The C vararg spec is not well-designed. If you pass all function arguments via the stack, va_start may be implemented pretty easily, but on the modern processor and in modern calling convention, arguments are passed via registers to reduce overhead of function calls. So the assumption of the spec does not match the reality.
The original assumption of the pre-ANSI <vararags.h> was that way, since it was just a hack exploiting actual object code behavior in the absence of language spec support. But ANSI C standardized the ... ellipsis, and the old hack became undefined behavior. A function declaration with the ellipsis is not type compatible with one that lacks it. This difference in type means that the compiler can map variadic functions to a different calling convention, such as one that always uses the stack for all the trailing arguments, even if they occur in positions for which the regular convention uses registers.
I wouldn't call variadic functions well designed on the whole, but aspect isn't badly designed.