passing non-dynamic arrays to variadic functions

MachineCode via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Oct 26 19:19:49 PDT 2014


On Monday, 27 October 2014 at 00:26:00 UTC, ketmar via 
Digitalmars-d-learn wrote:
> Hello.
>
> let's assume we have this code:
>
>   void doWrite(A...) (A args) {
>     import std.stdio;
>     import std.conv;
>     writeln(to!string(args[0]));
>   }
>
>   void main () {
>     char[3] a0 = "abc";
>     char[3] a1 = ['a', 'b', 'c'];
>     doWrite(a0);
>     doWrite(a1);
>   }
>
> i don't know why, but this code prints complete garbage each 
> time i

run
> it. yet if i'll change `doWrite()` invocations to this:
>
>     doWrite(a0[]);
>     doWrite(a1[]);
>
> everything is working fine.
>
> am i doing something wrong in the first sample and missed the 
> relevat
> part of documentation, or this is a bug? and do we have 
> workaround for
> this?

It worked fine for me. Output:

> abc
> abc

Environment: Win 8.1 64-bit (but dmd target is 32-bit, IIRC), dmd 
v2.066.0


More information about the Digitalmars-d-learn mailing list