Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Sequence points

Reply
Thread Tools

Sequence points

 
 
Senthil
Guest
Posts: n/a
 
      12-01-2005
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

 
Reply With Quote
 
 
 
 
Artie Gold
Guest
Posts: n/a
 
      12-01-2005
Senthil wrote:
> 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
>

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!"
 
Reply With Quote
 
 
 
 
Pete Becker
Guest
Posts: n/a
 
      12-01-2005
Senthil wrote:
>
> What are the sequence points inside these expressions?
>


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)
 
Reply With Quote
 
Senthil
Guest
Posts: n/a
 
      12-02-2005
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

 
Reply With Quote
 
Jack Klein
Guest
Posts: n/a
 
      12-02-2005
On 1 Dec 2005 19:56:14 -0800, "Senthil" <(E-Mail Removed)> wrote
in comp.lang.c++:

> 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


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
 
Reply With Quote
 
Senthil
Guest
Posts: n/a
 
      12-02-2005
Thanks a ton, Jack


-senthil

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Question about sequence points spibou@gmail.com C Programming 3 08-12-2006 10:01 PM
Knowing your sequence points akarl C Programming 7 08-12-2005 02:21 AM
Does C++ have sequence points ? Timothy Madden C++ 4 09-21-2004 08:21 AM
Sequence points Dave Theese C++ 2 09-03-2003 08:16 AM
Sequence points j C Programming 4 07-24-2003 11:14 AM



Advertisments