Pointer aliasing in D (Was: Programming language benchmarks)

Moritz Warning moritzwarning at web.de
Thu Apr 28 15:37:06 PDT 2011


On Thu, 28 Apr 2011 17:44:35 -0400, bearophile wrote:

> Walter:
> 
>> On 4/28/2011 11:44 AM, Jens Mueller wrote:
>> > Thanks. So if a compiler can assume that pointers do not alias it can
>> > generate much better code. What's D's standpoint on that matter then?
>> > C99 has restrict. I never came across something similar in D.
>> 
>> Const and immutable.
> 
> I don't understand. "restrict" means "this pointer has no alias". So how
> is const/immutable helping foo being optimized assuming a.ptr and b.ptr
> are distinct?
> 
> void foo(const float[] a, const float b[]) {} void main() {
>   const float[] a = [1.5, 2.5];
>   foo(a, a);
> }
When the contents are both const, then there won't be any writing
to it, of course. In that case the same optimizations can be applied as 
when they point to different memory.

both arrays point to different memory.


More information about the Digitalmars-d mailing list