Pointers to Dynamic Arrays

Brandon Ragland via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Aug 16 19:45:20 PDT 2015


Howdy,

Since Dynamic Arrays / Slices are a D feature, using pointers to 
these has me a bit confused...

Consider:

string c2s(int* pos, char[]* file, int l){
	char[] s;
	for(int i = 0; i < l; i++){
		s ~= file[(*pos + i)];
	}
	return s.dup;
}

Now what is especially confusing about this, is that the above 
seems to works fine, while this does not:

if(file[(*pos + i)] == '}'){
	*pos += i;
	return;
}

This fails with this error:
Error: incompatible types for ((file[cast(ulong)(*pos + i)]) == 
('}')): 'char[]' and 'char'

Now what I do not understand, is if the above works, by appending 
come chars gathered from the dynamic array via pointer to me new 
dynamic array named "s", and the below does not seem to work on 
comparison of two chars, what is really going on?

I can no longer assume that using the dynamic array pointer works 
anything like a standard pointer to an array, or a pointer to a 
dynamic array.

Is there something I'm missing?

Remember, that de-referencing a dynamic array was deprecated. So 
what I would normally have done: &dynamic_array_pntr does not 
work any longer, and there is no new spec on what to do...

-Brandon


More information about the Digitalmars-d-learn mailing list