473,385 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Purpose of sequence points

Hi all!

I do not have a standard-document right next to me to cite from, but as
far as I know, doing something like:

a()=b()=c()=d();
or
foo(d()+c()+b()+a());

has a fixed evaluation order (right-to-left in the first case and
left-to-right in the second one), although there are no sequence points
inside the =- or +-expression.

(Please correct me if I'm wrong here)

So, other than the order of evaluation of arguments to a function call:
foo(a(), b(), c(), d());

a, b, c and should be called in reverse order (d, c, b, a) for my first
two examples, right? For the third one, it is unspecified, AFAIK.

But when I do something like:
a=b=a=b or (++a)+(a++)

this is invalid due to multiple modification inbetween sequence points.
So here my question: What is the purpose of this rule, as in these
cases the order is well defined despite the fact there are no sequence
points? Is this to help the compiler optimize or could real ambiguities
occur?

Yours,
Daniel
--
Got two Dear-Daniel-Instant Messages
by MSN, associate ICQ with stress --
so please use good, old E-MAIL!
Jun 15 '07 #1
4 1746
Daniel Kraft wrote:
Hi all!

I do not have a standard-document right next to me to cite from, but as
far as I know, doing something like:

a()=b()=c()=d();
or
foo(d()+c()+b()+a());

has a fixed evaluation order (right-to-left in the first case and
left-to-right in the second one), although there are no sequence points
inside the =- or +-expression.

(Please correct me if I'm wrong here)
You're wrong. The compiler is free to calculate the operands a(), b(),
c(), and d() in any order. The order of the *arithmetic calculation* is
defined. The compiler can say "calcluate b(), then a(), then c(), then
d(), and store them in temps b, a, c, d, respecitvely. Then evaluate
((d + c) + b) +a. So the associativity and precedence of the operations
is defined, but the order of evaluation of the operands isn't.
Jun 15 '07 #2
red floyd wrote:
Daniel Kraft wrote:
>Hi all!

I do not have a standard-document right next to me to cite from, but
as far as I know, doing something like:

a()=b()=c()=d();
or
foo(d()+c()+b()+a());

has a fixed evaluation order (right-to-left in the first case and
left-to-right in the second one), although there are no sequence
points inside the =- or +-expression.

(Please correct me if I'm wrong here)

You're wrong. The compiler is free to calculate the operands a(), b(),
c(), and d() in any order. The order of the *arithmetic calculation* is
defined. The compiler can say "calcluate b(), then a(), then c(), then
d(), and store them in temps b, a, c, d, respecitvely. Then evaluate
((d + c) + b) +a. So the associativity and precedence of the operations
is defined, but the order of evaluation of the operands isn't.
I see -- but what is this restriction really for? To help the compiler
optimize the code? At least this is the only reason I can think of.

(Of course, this isn't really a restriction which hurts much; but it's
surely not there just for the sake of restricting the language)

Yours,
Daniel

--
Got two Dear-Daniel-Instant Messages
by MSN, associate ICQ with stress --
so please use good, old E-MAIL!
Jun 15 '07 #3
Daniel Kraft wrote:
red floyd wrote:
>Daniel Kraft wrote:
>>Hi all!

I do not have a standard-document right next to me to cite from, but
as far as I know, doing something like:

a()=b()=c()=d();
or
foo(d()+c()+b()+a());

has a fixed evaluation order (right-to-left in the first case and
left-to-right in the second one), although there are no sequence
points inside the =- or +-expression.

(Please correct me if I'm wrong here)

You're wrong. The compiler is free to calculate the operands a(),
b(), c(), and d() in any order. The order of the *arithmetic
calculation* is defined. The compiler can say "calcluate b(), then
a(), then c(), then d(), and store them in temps b, a, c, d,
respecitvely. Then evaluate ((d + c) + b) +a. So the associativity
and precedence of the operations is defined, but the order of
evaluation of the operands isn't.

I see -- but what is this restriction really for?
It's not a restriction. It would be a restriction if the order were
prescribed. Since it's unspecified, it's a non-restriction (what's
the antonym of 'restriction'?)
To help the
compiler optimize the code? At least this is the only reason I can
think of.
Not to help optimise but rather not to impede possible optimisations.
(Of course, this isn't really a restriction which hurts much; but it's
surely not there just for the sake of restricting the language)
It's there for exactly the opposite purpose - of NOT restricting.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 15 '07 #4
On Jun 15, 8:47 pm, Daniel Kraft <d...@domob.euwrote:
red floyd wrote:
Daniel Kraft wrote:
I do not have a standard-document right next to me to cite from, but
as far as I know, doing something like:
a()=b()=c()=d();
or
foo(d()+c()+b()+a());
has a fixed evaluation order (right-to-left in the first case and
left-to-right in the second one), although there are no sequence
points inside the =- or +-expression.
(Please correct me if I'm wrong here)
You're wrong. The compiler is free to calculate the operands a(), b(),
c(), and d() in any order. The order of the *arithmetic calculation* is
defined. The compiler can say "calcluate b(), then a(), then c(), then
d(), and store them in temps b, a, c, d, respecitvely. Then evaluate
((d + c) + b) +a. So the associativity and precedence of the operations
is defined, but the order of evaluation of the operands isn't.
I see -- but what is this restriction really for? To help the compiler
optimize the code? At least this is the only reason I can think of.
It makes it slightly easier for the compiler writer, by making
it a lot harder for you to test.
(Of course, this isn't really a restriction which hurts much; but it's
surely not there just for the sake of restricting the language)
Historically, with the primitive compiler technologies available
in the 1970's, it probably did make a difference. Today, I
doubt it.

--
James Kanze (Gabi Software) email: ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Jun 16 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Dave Theese | last post by:
Hello all, I have read the definition of a sequence point in the standard and can follow it mechanically, but for some reason, I'm having a hard time grasping the conceptual meaning and...
3
by: Sensorflo | last post by:
After browsing though many newsgroups articels I'm still not shure how operator precedence, operator associativity, sequence points, side effects go together. Currently I have the following view: ...
4
by: Timothy Madden | last post by:
Hello I've read a long time ago in the MSDN that C++ language defines no sequence points Now I read in the 1998 ISO standard a small list of sequence points in C++ Does C++ defines sequence...
53
by: Deniz Bahar | last post by:
I know the basic definition of a sequence point (point where all side effects guaranteed to be finished), but I am confused about this statement: "Between the previous and next sequence point an...
9
by: John Smith | last post by:
I've been playing with splint, which returns the following warning for the code below: statlib.c: (in function log_norm_pdf) statlib.c(1054,31): Expression has undefined behavior (left operand...
1
by: lovecreatesbea... | last post by:
---quoting--- Annex C (informative) Sequence points 1 The following are the sequence points described in 5.1.2.3: - The end of a full expression: an initializer (6.7.8); the expression in an...
2
by: ais523 | last post by:
The program excerpt int i; char c; char* a= {"abc","def","ghi"}; /* ... */ i=0; c=a; obviously invokes undefined behaviour, because i is modified twice
3
by: joe | last post by:
Consider the following program: include <iostream> class Bar { public: int getData9() { m_data = 9; return m_data;} int getData11() { m_data = 11; return m_data;} int m_data;
7
by: Jrdman | last post by:
hi According to the standard these are how we define sequence points: *the call to a function ,after the arguments have been evaluated *the end of the first operand of the following...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.