digitalmars.D.learn - expression
- Ellery Newcomer <ellery-newcomer utulsa.edu> May 29 2009
- Frits van Bommel <fvbommel REMwOVExCAPSs.nl> May 30 2009
- bearophile <bearophileHUGS lycos.com> May 30 2009
what is the purpose of the expression grammar Expression: AssignExpression AssignExpression , Expression ? (emphasis on the comma)
May 29 2009
Ellery Newcomer wrote:what is the purpose of the expression grammar Expression: AssignExpression AssignExpression , Expression ? (emphasis on the comma)
To allow two expressions separated by a comma to be another expression. This is only useful if the expression before the last comma has side-effects of course, since its value isn't used. Such an expression returns the result of its right-hand side. For example: (foo(), bar()) is an expression that calls foo(), then calls bar() and evaluates to the return value of bar(). This is mostly used in the increment clause of a for loop, like this: for (int i = 0; i < max; i++, someOtherCounter++)
May 30 2009
Frits van Bommel:To allow two expressions separated by a comma to be another expression. This is only useful if the expression before the last comma has side-effects of course, since its value isn't used. Such an expression returns the result of its right-hand side. For example: (foo(), bar()) is an expression that calls foo(), then calls bar() and evaluates to the return value of bar(). This is mostly used in the increment clause of a for loop, like this:
Outside for loops is a bug-prone and not much useful feature. (In python the comma is more useful and safer). Bye, bearophile
May 30 2009








bearophile <bearophileHUGS lycos.com>