🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: csu.cs.200
Article #120

Re: Pretty odd

#120
From: ken shrum
Date: Mon, 19 Oct 1998 00:00
20 lines
1190 bytes
douglas jackson (jacksond@alain.cs.colostate.edu) wrote:
[ this statement ]
: cout <<Stck1.Top_STK()<<Stck1.Pop_STK()<<endl;
[ and these statements ]
: cout <<Stck1.Top_STK();
: cout <<Stck1.Pop_STK()<<endl;
[ give different results ]
: Is there some sort of order of
: operations in a cout statement with classes?  

The technical term here is "sequence point" - the first statement
is a single expression, and it contains expressions with side-effects
(the "Top_STK" and "Pop_STK" calls).  Consequently, the Top and Pop
are evaluated in some undefined order before operator<< is invoked
to write to cout.

Your latter structure is more correct, or you can use temporary
variables to make the order of computation explicit.

    Ken Shrum
Technical Details
Message-ID: <70fnnp$607@alain.cs.colostate.edu>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <70d0pc$b8k2@yuma.ACNS.ColoState.EDU>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 127144,fbb7bbb1a356abdf
X-Google-Attributes: gid127144,public
From: shrum@alain.cs.colostate.edu (ken shrum)
Subject: Re: Pretty odd
Date: 1998/10/19
Message-ID: <70fnnp$607@alain.cs.colostate.edu>
X-Deja-AN: 402850341
References: <70d0pc$b8k2@yuma.ACNS.ColoState.EDU>
Organization: Computer Science Department, Colorado State University
Newsgroups: csu.cs.200