473,785 Members | 2,218 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1790
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.euw rote:
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*********@gma il.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
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
603
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 significance. Can someone out there offer good intuition on sequence points??? Thank you! Dave
3
2389
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: An expression a = b() + c() * d++; can be transformed with the rules of operator associativity and operator precedence into a tree
4
1669
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 points ? It really should if anyone asks me ... Thank you Timothy Madden
53
4096
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 object shall have its stored value modified at most once by the evaluation of an expression. Furthermore, the prior value shall be accessed only to determine the value to be stored." Can someone give me examples of expressions that "barely"...
9
2511
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 uses errno, modified by right operand): (log(x) - mu) * (log(x) - mu) Code has unspecified behavior. Order of evaluation of function parameters or subexpressions is not defined, so if a value is used and
1
2892
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 expression statement (6.8.3); ... ---quoting ends--- What does a full expression exactly mean?
2
1641
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
1687
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
215
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 operators : {logical AND :&&
0
9646
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9483
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9956
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8982
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7504
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6742
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5514
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4055
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2887
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.