pros and cons of a variadic function emulation approach

Viewed 104

I'm working on a platform on which we can compile C code (and other non-C things), but not variadic functions nor va_list's. I would like to emulate this mechanism - with a focus on simplicity/facility of implementation rather than optimum performance. I also want to avoid relying on ABI features, use of asm(), etc.

Naively, I was thinking about passing a number of arguments, an array of argument sizes, and an array of argument data (with the latter being either capped-size of dynamically allocated). And, of course, functions for constructing this stuff.

What are the pros and cons of this approach? Say, relative to an approach in which everything is in a single array, perhaps with some kind of null-pointer-termination a-la-argv? Or a proper list of nodes?

Also, am I reinventing the wheel and even the standard varags implementations already satisfy my requirements?

Notes:

  • The C variant is more-or-less C99. So no K&R loopholes, and no _Generic from C11.
  • It is the "user"'s responsibility to worry about type identification - using a format string, or some other parameters. Just like with the regular variable number of arguments.
0 Answers
Related