Looks like dereferencing a null pointer, but is ok???
nobody
nobody at mailinator.com
Mon Sep 11 14:31:03 PDT 2006
Georg Wrede wrote:
> In an old message,
>
>>> I don't think that any extra overhead is involved in slicing. D
>>> doesn't even check if a pointer is valid.
>>> (That might be a gotcha come to think of it)
>>>
>>> void main()
>>> {
>>> char[] foo = (cast(char*)null)[0..10];
>>> }
>>
>> Great example! I am now convinced there is nothing
>>> to worry about. Thanks everyone for the help!
>
> I'm baffled.
>
> I would have expected this to cause an error!
>
> And if really not, what in the world is
>
> (cast(char*)null)[0..10]
>
> supposed to mean, or return???
It is an array of the first 10 char elements starting from memory address 0.
More information about the Digitalmars-d-learn
mailing list