Connecting Tech Pros Worldwide Help | Site Map

Sequence points

  #1  
Old December 1st, 2005, 05:35 PM
Senthil
Guest
 
Posts: n/a
Hi,

When standard states this
"
i = v[i++]; // the behavior is undefined
i = ++i + 1; // the behavior is undefined
"

Do both of the following code snippets produces undefined behaviour or
the second one alone.

int m = 2;
int answer = ++m * ++m + ++m * ++m;

or

int m = 2
m = ++m * ++m + ++m * ++m;

What are the sequence points inside these expressions?

Thanks,
Senthil

  #2  
Old December 1st, 2005, 05:45 PM
Artie Gold
Guest
 
Posts: n/a

re: Sequence points


Senthil wrote:[color=blue]
> Hi,
>
> When standard states this
> "
> i = v[i++]; // the behavior is undefined
> i = ++i + 1; // the behavior is undefined
> "
>
> Do both of the following code snippets produces undefined behaviour or
> the second one alone.
>
> int m = 2;
> int answer = ++m * ++m + ++m * ++m;
>
> or
>
> int m = 2
> m = ++m * ++m + ++m * ++m;
>
> What are the sequence points inside these expressions?
>
> Thanks,
> Senthil
>[/color]
They both produce UB, as there *are* no sequence points in either
expression.

HTH,
--ag

--
Artie Gold -- Austin, Texas
http://goldsays.blogspot.com (new post 8/5)
http://www.cafepress.com/goldsays
"If you have nothing to hide, you're not trying!"
  #3  
Old December 1st, 2005, 07:35 PM
Pete Becker
Guest
 
Posts: n/a

re: Sequence points


Senthil wrote:[color=blue]
>
> What are the sequence points inside these expressions?
>[/color]

There aren't any. There is a sequence point at the end of each one. The
behavior of both statements is undefined, because they modify the value
of m more than once without an intervening sequence point.

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
  #4  
Old December 2nd, 2005, 04:05 AM
Senthil
Guest
 
Posts: n/a

re: Sequence points


Thanks Pete and Artie!!!

I read books and i read the standard..but i am still not able to
understand what a sequence point is ?
:(

Greetings,
Senthil

  #5  
Old December 2nd, 2005, 05:15 AM
Jack Klein
Guest
 
Posts: n/a

re: Sequence points


On 1 Dec 2005 19:56:14 -0800, "Senthil" <s.senthilvel@gmail.com> wrote
in comp.lang.c++:
[color=blue]
> Thanks Pete and Artie!!!
>
> I read books and i read the standard..but i am still not able to
> understand what a sequence point is ?
> :(
>
> Greetings,
> Senthil[/color]

Sequence points:

1. The ';' at the end of a full expression.

2. The comma operator (but the commas that separate arguments in a
function call are NOT comma operators).

3. At the '?' in the ternary expression.

4. During a function call, after all the arguments are evaluated,
before the function begins executing.

5. When a function ends/returns or exits by throwing an exception.

6. At the evaluation of a && or || logical operator.

7. At the initialization of each base and member in a constructor
with an initialization list.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
  #6  
Old December 2nd, 2005, 10:35 AM
Senthil
Guest
 
Posts: n/a

re: Sequence points


Thanks a ton, Jack


-senthil

Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
sequence points Jrdman answers 7 August 17th, 2008 08:15 PM
Purpose of sequence points Daniel Kraft answers 4 June 16th, 2007 12:05 PM
What are the sequence points in a full expression? lovecreatesbea...@gmail.com answers 1 October 9th, 2006 04:05 PM
Knowing your sequence points akarl answers 7 November 15th, 2005 01:46 AM
Does C++ have sequence points ? Timothy Madden answers 4 July 22nd, 2005 08:17 PM