www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - name shadowing in if statement

reply BCS <fubar pathlink.com> writes:
I think I saw something about this one but I couldn't find the post.

<code>
import std.stdio;

void main()
{
   int i = 1;

   if(int i = i)// new "i" shadows old "i"
   {
       i=6;
       witef("i=",i,\n);
   }
   witef("i=",i,\n);
}
</code>

<output>
i=6
i=1
</output>
Oct 07 2006
parent Thomas Kuehne <thomas-dloop kuehne.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

BCS schrieb am 2006-10-07:
 I think I saw something about this one but I couldn't find the post.

<code>
 import std.stdio;

 void main()
 {
    int i = 1;

    if(int i = i)// new "i" shadows old "i"
    {
        i=6;
        witef("i=",i,\n);
    }
    witef("i=",i,\n);
 }
</code>

<output>
 i=6
 i=1
</output>

Added to DStress as http://dstress.kuehne.cn/nocompile/i/if_15_A.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFFLk4sLK5blCcjpWoRAiyOAJwPxL51tEU4zDpwDksAcuz6cm556gCfS0Co W3epPWhOjbDOs+sIQB49huU= =d68l -----END PGP SIGNATURE-----
Oct 12 2006