[Issue 4172] New: Improve varargs

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon May 10 13:43:43 PDT 2010


http://d.puremagic.com/issues/show_bug.cgi?id=4172

           Summary: Improve varargs
           Product: D
           Version: future
          Platform: Other
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: nfxjfg at gmail.com


--- Comment #0 from nfxjfg at gmail.com 2010-05-10 13:43:40 PDT ---
Right now, "D-style Variadic Functions" provide _argptr and _arguments "magic"
variables. _argptr is just a pointer to the arguments, and getting the pointer
to each actual argument is very hard to implement. Actually it's _impossible_
to do in a portable way. Think of non-x86 architectures.

I propose the introduction of an additional _argarray variable, which is a
void*[]. Each array item should point to an argument's value, similar how each
item of _arguments contains the type of the argument.

Example:

void foo(...) {
   for (uint i = 0; i < _arguments.length; i++) {
     writefln("type of argument %s: %s", i, _arguments[i]);
     writefln("pointer to argument %s: %s", i, _argarray[i]);
   }
}

(Try that with to implement in a portable way without _argarray!)

This would also allow to implement positional format arguments more easily.

Note that there's the va_arg template, but it only works with argument types
known at compile time. For formatting functions and the like, you want to be
able to do everything at runtime.

This proposal is meant for both D1 and D2.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list