How does D cope with aliasing

grauzone none at example.net
Wed Sep 9 10:25:14 PDT 2009


#ponce wrote:
> Stewart Gordon Wrote:
>> My recollection of reading the spec is that a D compiler is allowed to 
>> optimise by assuming no pointer aliasing.  But I can't remember at the 
>> moment where I read this.
> 
> I don't know if this is neat or nasty for a compiler to do so. 
> 
> OT : Is there a DMD switch to disable bound check exceptions ? This way I wouldn't have to rely on pointers so much.

If you always want DMD never to bounds check for specific code, you just 
can write "a.ptr[index]" instead of "a[index]" (when a is an array). 
That's because array.ptr returns a pointer to the first element, and 
using [] on a pointer works exactly like C pointer math. The good thing 
about this is that you still can use array slices and the .length field, 
so the code most likely is less messy than the C version would be.


More information about the Digitalmars-d-learn mailing list