Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
January 10, 2014 What's going on here? | ||||
---|---|---|---|---|
| ||||
Attachments:
| So I'm interacting with C (although it works the same in D), I call a function that returns a pointer, and gives the size through an out arg: ubyte* test(size_t* ptr) { *ptr = 100; return cast(ubyte*)1234; } And call it, but immediately use the size argument to slice a range: size_t size; ubyte[] t = test(&size)[0..size]; t is null. If I do this, it works: size_t size; ubyte* pt = test(&size); ubyte[] t = pt[0..size]; Why should I need that extra line? |
January 10, 2014 Re: What's going on here? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manu | On 1/9/14 9:08 PM, Manu wrote:
> So I'm interacting with C (although it works the same in D), I call a
> function that returns a pointer, and gives the size through an out arg:
> ubyte* test(size_t* ptr)
> {
> *ptr = 100;
> return cast(ubyte*)1234;
> }
>
>
> And call it, but immediately use the size argument to slice a range:
> size_t size;
> ubyte[] t = test(&size)[0..size];
>
> t is null.
>
> If I do this, it works:
> size_t size;
> ubyte* pt = test(&size);
> ubyte[] t = pt[0..size];
>
> Why should I need that extra line?
It's a bug in the compiler. Evaluation should proceed as if it were strictly left to right. So test(&size) must be called before size is loaded to construct the slice. Please report.
Andrei
|
January 10, 2014 Re: What's going on here? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu Attachments:
| Reported. On 10 January 2014 15:34, Andrei Alexandrescu <SeeWebsiteForEmail@erdani.org > wrote: > On 1/9/14 9:08 PM, Manu wrote: > >> So I'm interacting with C (although it works the same in D), I call a >> function that returns a pointer, and gives the size through an out arg: >> ubyte* test(size_t* ptr) >> { >> *ptr = 100; >> return cast(ubyte*)1234; >> } >> >> >> And call it, but immediately use the size argument to slice a range: >> size_t size; >> ubyte[] t = test(&size)[0..size]; >> >> t is null. >> >> If I do this, it works: >> size_t size; >> ubyte* pt = test(&size); >> ubyte[] t = pt[0..size]; >> >> Why should I need that extra line? >> > > It's a bug in the compiler. Evaluation should proceed as if it were strictly left to right. So test(&size) must be called before size is loaded to construct the slice. Please report. > > Andrei > > |
January 10, 2014 Re: What's going on here? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Friday, 10 January 2014 at 05:34:27 UTC, Andrei Alexandrescu wrote:
> It's a bug in the compiler. Evaluation should proceed as if it were strictly left to right. So test(&size) must be called before size is loaded to construct the slice. Please report.
>
> Andrei
I remember this conversation popping up repeatedly. *Did* we ever make the choice to enforce this? I mean, is this part of the spec now? When did it happen? I seem to remember Walter was always against it.
|
January 11, 2014 Re: What's going on here? | ||||
---|---|---|---|---|
| ||||
Posted in reply to monarch_dodra | On Friday, January 10, 2014 07:24:43 monarch_dodra wrote:
> On Friday, 10 January 2014 at 05:34:27 UTC, Andrei Alexandrescu
>
> wrote:
> > It's a bug in the compiler. Evaluation should proceed as if it were strictly left to right. So test(&size) must be called before size is loaded to construct the slice. Please report.
> >
> > Andrei
>
> I remember this conversation popping up repeatedly. *Did* we ever make the choice to enforce this? I mean, is this part of the spec now? When did it happen? I seem to remember Walter was always against it.
Walter has stated that he wanted to, but AFAIK, it never actually became official. But knowing how things tend to go around here, even if Walter, Andrei, and all of the main devs thought that it was official, it still probably wouldn't be in the spec.
- Jonathan M Davis
|
January 11, 2014 Re: What's going on here? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | On Saturday, 11 January 2014 at 11:03:22 UTC, Jonathan M Davis wrote: > Walter has stated that he wanted to, but AFAIK, it never actually became > official. But knowing how things tend to go around here, even if Walter, > Andrei, and all of the main devs thought that it was official, it still > probably wouldn't be in the spec. > > - Jonathan M Davis It is in the spec[1]. [1] http://dlang.org/expression.html |
Copyright © 1999-2021 by the D Language Foundation