variadic (typesafe) args in DLL
Bjoern
nanali at nospam-wanadoo.fr
Fri Feb 8 10:55:54 PST 2008
Jarrett Billingsley schrieb:
> "Bjoern" <nanali at nospam-wanadoo.fr> wrote in message
> news:foi37b$19vv$1 at digitalmars.com...
>
>> export extern (Windows) uint BinaryOrPlus(uint...)
>> {
>> uint result = _arguments[0];
>> for (int i = 1; i < _arguments.length; i++)
>> {
>> result |= _arguments[i];
>> }
>> return result;
>> }
>>
>> Unfortunately Error msg is :
>>
>> C:\dmd\projects\bsdutil>dmd -profile -odc:\dmd\projects\bsdutil\obj -ofBSDUTIL.D
>> LL bsdutil.d demangle.d bsdutil.def
>> bsdutil.d(110): Error: undefined identifier _arguments
>> bsdutil.d(110): Error: _arguments must be an array or pointer type, not
>> int
>
> Ur typesafe variadic function, ur doin it wrong.
>
> You declare the typesafe variadic param as so:
>
> uint BinaryOrPlus(uint[] vals...)
>
> then just use vals.
How to iterate over vals ?
>
> Typesafe variadic params are just sugar for passing an array literal. In
> fact you can also pass an array reference in place of a list of params.
>
> To that end, unless 4GL supports passing D arrays, you're going to have to
> do something else.
I can only use C style fixed arrays but this will end in code like
arr is fixed array on 3 uint = [WS_HONK, WS_TONK, WS_ITCH]
so, no win for me
>
>
okay let's forget about "typesafe" I can manage this in 4GL code,
however following the D guidelines this should work :
export extern (Windows) uint BinaryOrPlus(uint firstarg, ...)
{
uint result = firstarg; //_arguments[0];
for (int i = 1; i < _arguments.length; i++)
{
result |= *cast(uint *)_argptr;
_argptr += uint.sizeof;
}
return result;
}
In fact it don't work and it is looks dirty. they question here is ;
what is the matter with _arguments /// using Tango
Thanks for spending your time
Bjoern
More information about the Digitalmars-d-learn
mailing list