www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Bug or feature?

reply "mimi" <4.deniz.z.z gmail.com> writes:
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
May 26 2013
parent reply "Maxim Fomin" <maxim maxim-fomin.ru> writes:
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)
May 26 2013
parent reply "mimi" <4.deniz.z.z gmail.com> writes:
Well, how you can reduce the long ugly name in this case? In the 
real function I mentioned it so many times.
May 27 2013
next sibling parent reply "Namespace" <rswhite4 googlemail.com> writes:
void foo( S s )
{
	auto local = this.bigUglyName;
	auto b = s.bigUglyName;

	writeln( "bigUglyName (AKA local)=", local, " b=", b );
}

:P
May 27 2013
parent "mimi" <4.deniz.z.z gmail.com> writes:
On Monday, 27 May 2013 at 10:17:01 UTC, Namespace wrote:
 void foo( S s )
 {
 	auto local = this.bigUglyName;
 	auto b = s.bigUglyName;

 	writeln( "bigUglyName (AKA local)=", local, " b=", b );
 }

 :P
By the way, yes. Thanks for that, I'm stupid today.
May 27 2013
prev sibling parent reply "Maxim Fomin" <maxim maxim-fomin.ru> writes:
On Monday, 27 May 2013 at 10:07:49 UTC, mimi wrote:
 Well, how you can reduce the long ugly name in this case? In 
 the real function I mentioned it so many times.
By not making the name ugly big.
May 27 2013
parent "mimi" <4.deniz.z.z gmail.com> writes:
On Monday, 27 May 2013 at 11:32:46 UTC, Maxim Fomin wrote:
 On Monday, 27 May 2013 at 10:07:49 UTC, mimi wrote:
 Well, how you can reduce the long ugly name in this case? In 
 the real function I mentioned it so many times.
By not making the name ugly big.
Other people do. In addition, sometimes you want to cut long nested queries such as: auto numOfPixelsDisplayed = Table.getItems( Scene.getObjectsArray() ).prepareForDisplay( type.GL ).showScene();
May 27 2013