digitalmars.D.bugs - assignment in ? operator
- Ilya Zaitseff (10/10) Sep 05 2004 [bug.d]
- Stewart Gordon (27/40) Sep 06 2004 http://www.digitalmars.com/d/expression.html
- Ilya Zaitseff (2/36) Sep 06 2004 You right. Thanks!
[bug.d] void main() { int a, b, c; (a < 0) ? b = 1 : c = 2; } Compiler [dmd 0.101] outputs: bug.d(4): b = 1 is not an lvalue bug.d(4): #b = 1 is not an lvalue bug.d(4): #c is not an lvalue
Sep 05 2004
Ilya Zaitseff wrote:[bug.d] void main() { int a, b, c; (a < 0) ? b = 1 : c = 2; } Compiler [dmd 0.101] outputs: bug.d(4): b = 1 is not an lvalue bug.d(4): #b = 1 is not an lvalue bug.d(4): #c is not an lvaluehttp://www.digitalmars.com/d/expression.html AssignExpression: ConditionalExpression ConditionalExpression = AssignExpression ConditionalExpression += AssignExpression ConditionalExpression -= AssignExpression ConditionalExpression *= AssignExpression ConditionalExpression /= AssignExpression ConditionalExpression %= AssignExpression ConditionalExpression &= AssignExpression ConditionalExpression |= AssignExpression ConditionalExpression ^= AssignExpression ConditionalExpression ~= AssignExpression ConditionalExpression <<= AssignExpression ConditionalExpression >>= AssignExpression ConditionalExpression >>>= AssignExpression ConditionalExpression: OrOrExpression OrOrExpression ? Expression : ConditionalExpression So your code means ((a < 0) ? b = 1 : c) = 2; You need to tell it otherwise. Stewart. -- My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Sep 06 2004
Stewart Gordon wrote:Ilya Zaitseff wrote:You right. Thanks![bug.d] void main() { int a, b, c; (a < 0) ? b = 1 : c = 2; } Compiler [dmd 0.101] outputs: bug.d(4): b = 1 is not an lvalue bug.d(4): #b = 1 is not an lvalue bug.d(4): #c is not an lvaluehttp://www.digitalmars.com/d/expression.html AssignExpression: ConditionalExpression ConditionalExpression = AssignExpression ConditionalExpression += AssignExpression ConditionalExpression -= AssignExpression ConditionalExpression *= AssignExpression ConditionalExpression /= AssignExpression ConditionalExpression %= AssignExpression ConditionalExpression &= AssignExpression ConditionalExpression |= AssignExpression ConditionalExpression ^= AssignExpression ConditionalExpression ~= AssignExpression ConditionalExpression <<= AssignExpression ConditionalExpression >>= AssignExpression ConditionalExpression >>>= AssignExpression ConditionalExpression: OrOrExpression OrOrExpression ? Expression : ConditionalExpression So your code means ((a < 0) ? b = 1 : c) = 2; You need to tell it otherwise. Stewart.
Sep 06 2004