Bug or feature?

Maxim Fomin maxim at maxim-fomin.ru
Sun May 26 22:05:34 PDT 2013


On Sunday, 26 May 2013 at 23:35:43 UTC, mimi wrote:
> import std.stdio;
>
> struct S
> {
>     int bigUglyName;
>
>     void foo( S s )
>     {
>         alias bigUglyName local;
>         alias s.bigUglyName b;
>
>         writeln( "bigUglyName (AKA local)=", local, " b=", b );
>     }
> }
>
> void main()
> {
>     S s1;
>     S s2;
>
>     s1.bigUglyName = 1;
>     s2.bigUglyName = 2;
>
>     s1.foo( s2 );
> }
>
>
> returns to console:
> bigUglyName (AKA local)=1 b=1
>
> Why? I am expected that b=2

alias does not capture this pointer, it is rewritten as 
S.bigUglyName and you can refer to non-static fields as 
Type.member which is this.member in member functions  (in D 
semantic differences of accessing static and non-static members 
are diluted)


More information about the Digitalmars-d-learn mailing list