|
Archives
D Programming
digitalmars.Ddigitalmars.D.bugs digitalmars.D.dtl digitalmars.D.ide digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger D.gnu D C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript electronics |
digitalmars.D - runtime vararg can easily be broken
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/
Jun 12 2009
davidl wrote: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. Jun 12 2009
davidl wrote:The runtime vararg push into stack with align of 4, however programmer might neglect this easily and cause problem. ... Jun 12 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. ... Jun 12 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. ... Jun 13 2009
在 Sat, 13 Jun 2009 02:17:03 +0800,Daniel Keep <daniel.keep.lists gmail.com> 写道:davidl wrote:The runtime vararg push into stack with align of 4, however programmer might neglect this easily and cause problem. ... Jun 12 2009
|