[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: variable args
- From: virgil@... (Virgil Smith)
- Date: Fri, 21 Nov 2003 11:02:07 -0600
>If the API with which you are working provides this option, it would be
>a relatively simple task to bundle your Lua arguments into an array and
>call the "v" flavor function.
>
>Kurt Jung
Great advice, but minor editing comment, "array" should be "buffer" and as
someone else pointed out this won't be portable (or at least it will have
"issues").
By "buffer" I mean you'll have to do some "nasty" C-style type mangling
using a char* into a buffer, casting it to the appropriate pointer type for
the type of argument you are currently handling, incrementing the pointer
value by an appropriate amount for that argument, and then repeating the
process. The "issues" with this are issues such as memory access alignment
concerns and how the compiler vendor chose to implement vararg functions
(again their choices are likely to be driven by memory alignment issues and
the fact that so long as they provide suitable access macros they can shove
parameters on the stack in any manner they choose). Also, if your platform
does not use a consistent size of pointer then you've really got "issues".
However, IIRC vararg function arguments disallow "smaller" types. For
instance, a char, short, or int will be converted "up" to a long. A float
will be converted "up" to a double. With just a little luck your platform
uses a consistent pointer size, and even if it does not then varargs
functions probably "cast" all pointers to some "full" size (i.e. a "far"
pointer or similar). Thus you may be able to reduce the number of parameter
options down to 3 (long, double, and X*), so if you have to write C helper
functions to arrange the parameters the number of helpers you need to write
is "merely" the sequence sum(i=0..N, 3^i) where N is the maximum number of
parameters.
Good Luck, and let us know how it turns out.