Feature request: extending comma operator's functionality

Tommi tommitissari at hotmail.com
Thu Oct 4 14:11:58 PDT 2012


Could you change it so that expressions, that are separated by 
commas and inside an if-clause, would have visibility to the 
variable defined in the first expression? Easier to show than to 
explain:

int getInt()
{
     return 11;
}

void main()
{
     if (int n = getInt(), n > 10) // undefined identifier n
     {
         //...
     }

     if (int n = getInt(), ++n, n > 10) // undefined identifier n
     {
         //...
     }

     if (int n = getInt(), getInt() > 10) // OK
     {
         //...
     }
}

That would make it possible to define variables in the smallest 
possible scope, and not pollute the namespace of the enclosing 
scope.


More information about the Digitalmars-d mailing list