www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - assignment in ? operator

reply "Ilya Zaitseff" <sark7 mail333.com> writes:
[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
parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
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 lvalue

http://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
parent "Ilya Zaitseff" <sark7 mail333.com> writes:
Stewart Gordon wrote:

 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 lvalue

http://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.

You right. Thanks!
Sep 06 2004