array.reverse segfaults

Moritz Warning moritzwarning at web.de
Wed Oct 22 03:56:49 PDT 2008


On Wed, 22 Oct 2008 19:28:08 +0900, Bill Baxter wrote:

> On Wed, Oct 22, 2008 at 7:16 PM, Moritz Warning <moritzwarning at web.de>
> wrote:
>> Hi,
>>
>> This piece of code segfaults on Debian Linux (with dmd 1.035): Can
>> someone tell me why?
>>
>> char[] get(char[] str)
>> {
>>    return new char[](4);
>> }
>>
>> void main(char[][] args)
>> {
>>    char[] str =  get("abc");
>>   char[] reversed = str.reverse; // <-- access violation
>> }
> 
> Does str.reverse actually return anything? I think you need to do that
> as:
>    str.reverse;
>    char[] reversed = str;
> 
> However, if it's not supposed to return anything, then it's a bug that
> it compiles.
> If it's supposed to return something, then it's a bug that it crashes.
> Does it work doing it as two lines?
> 
> --bb

>From the specs:
.reverse  	Reverses in place the order of the elements in the array. 
Returns the array. 

Removing the assignment to "reversed" doesn't change anything.



More information about the Digitalmars-d mailing list