Slincing behaviour

Steven Schveighoffer schveiguy at yahoo.com
Fri Nov 11 11:01:42 PST 2011


On Fri, 11 Nov 2011 13:29:17 -0500, Simon <s.d.hammett at gmail.com> wrote:

> On 11/11/2011 16:56, Nick Sabalausky wrote:
>> "Jonathan M Davis"<jmdavisProg at gmx.com>  wrote in message
>> news:mailman.866.1321013026.24802.digitalmars-d-learn at puremagic.com...
>>> On Friday, November 11, 2011 11:46:02 RenatoL wrote:
>>>> int[7] arr = [1,2,3,4,5,6,7];
>>>> writeln(arr[$..$]);
>>>>
>>>> this simply prints a newline... I expected a runtime error (or better
>>>> a compile time error) but it does nothing ... why?
>>>
>>> Probably because it's length is zero and therefore isn't actually a  
>>> slice
>>> of
>>> the original array at all. It wouldn't surprise me if arr[500 .. 500]
>>> worked
>>> exactly the same way. Because the array is empty, it doesn't really  
>>> matter
>>> what values you gave it.
>>>
>>
>> Weird, I was certain that had given me bounds errors before, and so I've
>> been careful to avoid doing it. Maybe that's changed since I last tried  
>> it.
>>
>>
>
> You get bounds error in debug, but not release.
> The bit about slices says you must not depend on bounds checking.
>

There should be no bounds error in any case, an empty slice is valid.

-Steve


More information about the Digitalmars-d-learn mailing list