Any way to set len and ptr in dyn arrays?

Tue Aug 8 10:10:09 PDT 2006

Frank Benoit wrote:
>>>This builds a slice, which is like setting ptr/length of an array. This
>>>is called slicing. Instead of Toms example, I think you can also write
>>>foo = buf[ 2 .. buf[0] * buf[1] + 2 ];
>>Thanks to you also for your response. I was trying to suggest before
>>that I understand how slicing ends up -- ie with ptr and len as I
>>desired. I am worried about what happens while the slicing happens. I am
>>worried about any gotchas.
> I my understanding this is exactly like setting the ptr and length.
> One side effect could be, that the compiler perhaps inserts array
> boundary check. But I don't know that.

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];

More information about the Digitalmars-d-learn mailing list