TITLE: sequence points and built-in operators (Newsgroups: comp.std.c++, 17 Feb 99) Subject: Re: Preincrement yields lvalue? ???: >> int i = 0; >> ++i = 5; NARAN: sbnaran@localhost.localdomain.COM (Siemel Naran) >The above code is well defined, I think, and should result in i >equal to 5. It is equivalent to, > operator=(operator++(i),5); // before, 'i' is 0 CLAMAGE: Steve Clamage, stephen.clamage@sun.com No. Have a look at section 1.9 for a discussion of sequence points. The only sequence point in the last line occurs at the end of the expression. Both the pre-increment and the assignment attempt to modify the value of i, each modification being a side effect. The code has undefined results. Although it is likely the result will be either 1, 5, or 6, and nothing horrible will happen, the compiler is allowed to diagnose the error and refuse to compile the code. You discussion of operator= and operator++ applies only for interpreting the rules about overloaded operators. Quoting from 13.6, "Built-in operators": "The candidate operator functions that represent the built-in operators defined in clause 5 are specified in this subclause. These candidate functions participate in the operator overload resolution process as described in 13.3.1.2 and are used for no other purpose." Thus, you cannot use function-call semantics to infer sequence points for built-in operators. I'm sure someone will question how the result of the undefined operation could be 1, 5, or 6. Assume that i is in memory, and the machine can do arithmetic only in registers, but can assign literal values to memory locations. So after i is initialized to zero, we could have A: reg=i; i=5; reg+=1; i=reg; ==> 1 B: reg=i; reg+=1; i=reg; i=5; ==> 5 C: i=5; reg=i; reg+=1; i=reg; ==> 6