Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > What is sequence point ?

Thread Tools

What is sequence point ?

Posts: n/a
Can somebody explain to me what is sequence point ?
With few examples would be even better. Thanx for your help.
Reply With Quote
Joona I Palaste
Posts: n/a
sugaray <(E-Mail Removed)> scribbled the following:
> Can somebody explain to me what is sequence point ?
> With few examples would be even better. Thanx for your help.

A sequence point is a point of time in the evaluation of a C expression,
where all side effects are guaranteed to have taken place.
Modifying the same variable twice, or modifying a variable and using its
old value for anything other than computing the new value, without a
sequence point in between, causes undefine behaviour.
If I remember correctly, sequence points include:
- The , (comma) and ?: (conditional) operators,
- The && and || operators,
- The semicolon at the end of a statement, and
- The entry point to a function, but this only concerns expressions
within that function.
Most importantly, the assignment operators (such as =), the pre-
and post- increment and decrement operators (++ and --), and the
comma *separator* in parameter lists are NOT sequence points.

/-- Joona Palaste ((E-Mail Removed)) ------------- Finland --------\
\-- --------------------- rules! --------/
"Holy Banana of this, Sacred Coconut of that, Magic Axolotl of the other."
- Guardian in "Jinxter"
Reply With Quote
Martin Dickopp
Posts: n/a
      03-01-2004 Removed) (sugaray) writes:

> Can somebody explain to me what is sequence point ?

Read the FAQ, please. (Q3.


,--. Martin Dickopp, Dresden, Germany ,= ,-_-. =.
/ ,- ) ((_/)o o(\_))
\ `-' `-'(. .)`-'
`-. Debian, a variant of the GNU operating system. \_/
Reply With Quote
Manish Singh
Posts: n/a
(E-Mail Removed) (sugaray) wrote in message news:<(E-Mail Removed). com>...
> Can somebody explain to me what is sequence point ?
> With few examples would be even better. Thanx for your help.

Joona has already explained the sequence points and its basic workings.
However, one thing he missed is the test condition of the while loop.
For a better cover of the sequence points, side effects and full expressions,
you need to consult a good book and/or C-FAQs.

As you asked for examples, here is one including a while loop sequence point.

#include <stdio.h>
int main(void)
int i;

for(i = 1; i <= 10; i++)
printf("%d\n", i);

i = 1;
while(i++ <= 10)
printf("%d\n", i);

return 0;

As you can see, in the for construct i is initialized to 1, then tested with
the value 10 and finally incremented after executing the printf() statement.
I don't think there is a need to explain the workings of the for loop, is it?
It normally prints the value of i from 1 to 10 on your output device, along
with newlines.

Then, we reset i to 1.
Notice that the while loop can be made to imitate the for loop, quite easily.
It appears that i will get incremented only after the printf() has done it job.
This way, the while loop should also print the values from 1 to 10, after all
this is what post-increment operator does, isn't it?

Not quite so. The while loop test condition serves as a sequence point. So,
in this case, i gets incremented immediately before the printf() receives
control. Side effect of this condition test is that i will get incremented
before the program reaches printf() statement. In the end, values from 2 to
11 will be printed on your output device.

But, what if you change the postfix form of i to prefix form? It still won't
help too much. It will only stop incrementing i after comparing it with 10,
thus resulting in printing of values 2 to 10.

Manish Singh
Reply With Quote

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
Share-Point-2010 ,Share-Point -2010 Training , Share-point-2010Hyderabad , Share-point-2010 Institute Saraswati lakki ASP .Net 0 01-06-2012 06:39 AM
how to iterate over sequence and non-sequence ? stef mientki Python 13 10-20-2007 10:21 AM
Scenario 5: IS-IS routing on Frame Relay Multi-point and Point-to-Point David Sudjiman Cisco 0 06-08-2006 09:11 AM
precedence, sequence point, side effect Sensorflo C++ 3 08-19-2004 12:52 PM
BOOT SEQUENCE (how to change boot sequence) bird Computer Support 13 12-24-2003 02:20 AM