Pointer aliasing in D (Was: Programming language benchmarks)
bearophile
bearophileHUGS at lycos.com
Thu Apr 28 14:44:35 PDT 2011
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);
}
Bye,
bearophile
More information about the Digitalmars-d
mailing list