What's going on here?

Manu turkeyman at gmail.com
Thu Jan 9 22:47:06 PST 2014


Reported.


On 10 January 2014 15:34, Andrei Alexandrescu <SeeWebsiteForEmail at 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20140110/a8c5edf8/attachment-0001.html>


More information about the Digitalmars-d mailing list