www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - if(int a = 0) lowered to "if (int a = (int a = 1;) , a)" ?

reply aliak <something something.com> writes:
Found this out while just looking at lowerings. Wondering if 
anyone knows the semantics involved here and where they are 
documented?

And, is there anyway to do it with multiple variables?

I.e.

if (int a = 0, int b = 0) {
  // ...
}


Cheers,
- Ali
Aug 08 2018
next sibling parent Jonathan M Davis <newsgroup.d jmdavisprog.com> writes:
On Wednesday, August 8, 2018 5:58:50 AM MDT aliak via Digitalmars-d-learn 
wrote:
 Found this out while just looking at lowerings. Wondering if
 anyone knows the semantics involved here and where they are
 documented?
It's particularly useful when dealing with stuff like C functions that return 0 on success or getting values from AAs. e.g. if(auto value = key in aa) { }
 And, is there anyway to do it with multiple variables?

 I.e.

 if (int a = 0, int b = 0) {
   // ...
 }
I don't believe so. - Jonathan M Davis
Aug 08 2018
prev sibling parent reply Alex <sascha.orlov gmail.com> writes:
On Wednesday, 8 August 2018 at 11:58:50 UTC, aliak wrote:
 Found this out while just looking at lowerings.
How do you "look at lowerings"? Is there a list, I'm not aware of? ;)
Aug 08 2018
parent reply aliak <something something.com> writes:
On Wednesday, 8 August 2018 at 12:58:24 UTC, Alex wrote:
 On Wednesday, 8 August 2018 at 11:58:50 UTC, aliak wrote:
 Found this out while just looking at lowerings.
How do you "look at lowerings"? Is there a list, I'm not aware of? ;)
Go here https://run.dlang.io/is/tJ4vXm and click on the AST button :) It shows you what the code turns in to after all the semantic passes.
Aug 08 2018
parent Alex <sascha.orlov gmail.com> writes:
On Wednesday, 8 August 2018 at 13:13:24 UTC, aliak wrote:
 Go here https://run.dlang.io/is/tJ4vXm and click on the AST 
 button :) It shows you what the code turns in to after all the 
 semantic passes.
Yeah... no... I'm aware of this cool thing )) I thought you have a hidden source of knowledge, where all available transformations back and fore are specified, somehow... ))
Aug 08 2018