3 variant questions

grauzone none at example.net
Tue May 12 09:41:36 PDT 2009


Dear Saaa, these varargs suck badly and you shouldn't use them. It's so 
simple to introduce portability errors or heisenbugs, and it's 
incredibly hard to get it right. You're better off with alternatives.

Alternative 1: Typesafe Variadic Functions
Useful if the variadic arguments should have only one type. And they're 
very easy to use. It's documented somewhere on 
http://www.digitalmars.com/d/1.0/function.html

Alternative 2: Tuples
http://www.digitalmars.com/d/1.0/template.html#TemplateTupleParameter
The variadic arguments can have any types, but such functions can't 
really be virtual methods or delegates.

>> Why is this extra step necessary and why won't simple casting not work?
> 
> You should never directly work with _argptr.  It's not guaranteed to be
> a simple pointer.  For example, I believe that GCC will sometimes use
> registers (God only knows WHY).

I think it's because GCC tries to keep the usual calling convention, 
where some arguments are passed as registers. Which is utterly pointless 
and stupid (ok, maybe it was easier to implement in gdc), and turns 
using varargs into hell.

It would be so simple if _argptr was just an array of pointers to the 
actual arguments. It'd be so simple it makes me mad.


More information about the Digitalmars-d-learn mailing list