runtime vararg can easily be broken

Jason House jason.james.house at gmail.com
Sat Jun 13 10:44:06 PDT 2009


grauzone Wrote:

> 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.

All non-digitalmars D compilers I've seen have done alternate implementations for this.

 
> "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