Connecting Tech Pros Worldwide Forums | Help | Site Map

undefined behaviour

subramanian100in@yahoo.com, India
Guest
 
Posts: n/a
#1: Mar 5 '07
Suppose

int i = 2;

i = ++i + 1;

Please explain whether the evaluation of this statement, has undefined
behaviour ?


santosh
Guest
 
Posts: n/a
#2: Mar 5 '07

re: undefined behaviour


subramanian100in@yahoo.com, India wrote:
Quote:
Suppose
>
int i = 2;
>
i = ++i + 1;
>
Please explain whether the evaluation of this statement, has undefined
behaviour ?
Yes, you're modifying an object twice without an intervening sequence
point. In such cases, the order of evaluation of the expression is
undefined by the standard, though a particular implementation might
happen to produce results that you might consider appropriate.

santosh
Guest
 
Posts: n/a
#3: Mar 5 '07

re: undefined behaviour



subramanian100in@yahoo.com, India wrote:
Quote:
Suppose
>
int i = 2;
>
i = ++i + 1;
>
Please explain whether the evaluation of this statement, has undefined
behaviour ?
In case you don't know yet, this group has a very useful FAQ at
http://www.c-faq.com/

It'll help you avoid asking questions, like this one, that've been
beaten to death over the years here.

subramanian100in@yahoo.com, India
Guest
 
Posts: n/a
#4: Mar 5 '07

re: undefined behaviour


What is a sequence point

santosh
Guest
 
Posts: n/a
#5: Mar 5 '07

re: undefined behaviour



subramanian100in@yahoo.com, India wrote:
Quote:
What is a sequence point
See comp.lang.c's FAQ at http://www.c-faq.com/

Your question is explained at:

<http://c-faq.com/expr/seqpoints.html>

Sharath
Guest
 
Posts: n/a
#6: Mar 5 '07

re: undefined behaviour


On Mar 5, 9:47 am, "subramanian10...@yahoo.com, India"
<subramanian10...@yahoo.comwrote:
Quote:
Suppose
>
int i = 2;
>
i = ++i + 1;
>
Please explain whether the evaluation of this statement, has undefined
behaviour ?
Yes, it does have undefined behavior. Because the value of 'i' is
modified more than once between sequence points.

William Ahern
Guest
 
Posts: n/a
#7: Mar 5 '07

re: undefined behaviour


On Sun, 04 Mar 2007 20:47:20 -0800, subramanian100in@yahoo.com, India
wrote:
Quote:
Suppose
>
int i = 2;
>
i = ++i + 1;
>
Please explain whether the evaluation of this statement, has undefined
behaviour ?
You go first.
Closed Thread