runtime vararg can easily be broken

davidl davidl at nospam.org
Fri Jun 12 09:47:35 PDT 2009


The runtime vararg push into stack with align of 4, however programmer  
might neglect this easily and cause problem.

import std.boxer;
import std.stdio;
void func(...)
{
   Box[] arguments;
   arguments.length = _arguments.length;
   for(int i;i<_arguments.length;i++)
   {
      arguments[i] = box(_arguments[i], _argptr);
      _argptr += _arguments[i].tsize;
   }
   foreach(arg;arguments)
      writefln(arg);
}
void main()
{
   func(34,43);
   func(cast(ushort)4, cast(ushort)5); // this fails
}

I don't know if tango Stdout suffers from this.
But this really can easily cause problems.
Also the whole paradigm of coding a runtime vararg func is so troublesome  
and even much complex compared to the compile time vararg. Maybe we should  
borrow something from compiletime to aid the runtime vararg programming.


-- 
使用 Opera 革命性的电子邮件客户程序: http://www.opera.com/mail/



More information about the Digitalmars-d mailing list