runtime vararg can easily be broken
grauzone
none at example.net
Fri Jun 12 23:15:26 PDT 2009
Daniel Keep wrote:
>
> davidl wrote:
>> The runtime vararg push into stack with align of 4, however programmer
>> might neglect this easily and cause problem.
>>
>> ...
>>
>
> That's because you're not supposed to do that.
>
> std.stdarg
Contains only a template. Here's the solution (untested):
void* va_arg(inout void* _argptr, TypeInfo ti) {
void* result = _argptr;
_argptr = _argptr + ((ti.tsize + int.sizeof - 1) & ~(int.sizeof - 1));
return arg;
}
(int.sizeof is always 4, but I doubt the original code runs correctly on
anything but 32 bit x86 anyway.)
We all know that (dynamic) varargs in D really, really suck. A lot of
simple enough solutions have been proposed. But nothing happens.
"The trivialer the solution, the more likely it is that the problem
itself will never be solved and the programmer always has to fight with
this trivial garbage."
More information about the Digitalmars-d
mailing list