Thread overview
passing non-dynamic arrays to variadic functions
Oct 27, 2014
ketmar
Oct 27, 2014
anonymous
Oct 27, 2014
Ali Çehreli
Oct 27, 2014
ketmar
Oct 27, 2014
ketmar
Oct 27, 2014
MachineCode
Oct 27, 2014
ketmar
Oct 27, 2014
MachineCode
Oct 27, 2014
ketmar
October 27, 2014
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?


October 27, 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

Prints
abc
abc
for me.
October 27, 2014
On 10/26/2014 05:33 PM, anonymous wrote:
> 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
>
> Prints
> abc
> abc
> for me.

Yeah, works with git head.

Ali

October 27, 2014
On Mon, 27 Oct 2014 00:33:13 +0000
anonymous via Digitalmars-d-learn <digitalmars-d-learn@puremagic.com>
wrote:

> 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
> 
> Prints
> abc
> abc
> for me.
ah, i forgot to specify my system:
GNU/Linux, x86, DMD git head. could you please test this with current
git?

it seems to work with GDC, which is 2.065 for now. seems that this is a regression.


October 27, 2014
On Sun, 26 Oct 2014 17:41:28 -0700
Ali Çehreli via Digitalmars-d-learn <digitalmars-d-learn@puremagic.com>
wrote:

> Yeah, works with git head.
ah, thank you. seems that one of the custom patches i'm using broke that. i just checked this on unpatched DMD, and it works too.

sorry for the noise.


October 27, 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
October 27, 2014
On Mon, 27 Oct 2014 02:19:49 +0000
MachineCode via Digitalmars-d-learn <digitalmars-d-learn@puremagic.com>
wrote:

> 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
yes, thank you too. that was one of my custom patches that broke this. i already found that patch, and it's not even mine! ;-)


October 27, 2014
On Monday, 27 October 2014 at 02:27:32 UTC, ketmar via Digitalmars-d-learn wrote:
> On Mon, 27 Oct 2014 02:19:49 +0000
> MachineCode via Digitalmars-d-learn <digitalmars-d-learn@puremagic.com>
> wrote:
>
>> 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
> yes, thank you too. that was one of my custom patches that broke this.
> i already found that patch, and it's not even mine! ;-)

You're welcome :) what do you call git head is the dmd compiler compiled from dmd's source code on github?
October 27, 2014
On Mon, 27 Oct 2014 03:07:12 +0000
MachineCode via Digitalmars-d-learn <digitalmars-d-learn@puremagic.com>
wrote:

> You're welcome :) what do you call git head is the dmd compiler compiled from dmd's source code on github?
yes. i'm updating my compiler on dayly basis, so my "git head" is really "head". ;-)

but i also have alot of custom patches applied to it (some not-yet-accepted PRs, my internal patches that will never made into mainline and so on). usually i'm trying to reproduce the bug with "vanilla" DMD, but this time i was so sure that it's in vanilla too that i didn't bother to check. my bad.