Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #11030

Re: Help with post-increment and sequence points

From laird@lbreyer.com
Newsgroups comp.lang.c++
Subject Re: Help with post-increment and sequence points
Date 2011-10-20 14:16 -0700
Organization http://groups.google.com
Message-ID <16331545.1098.1319145393057.JavaMail.geo-discussion-forums@prfp13> (permalink)
References <26287949.549.1319095405219.JavaMail.geo-discussion-forums@prfp13> <j7p41q$lt3$1@dont-email.me>

Show all headers | View raw


On Thursday, 20 October 2011 23:26:33 UTC+11, Victor Bazarov  wrote:
> >
> > Shouldn't this actually be equivalent to
> f(f(f(f(std::cout,i),i++),i),"\n") where f is operator<< ? In that case,
> each time a function is entered, there should be a sequence point which
> makes the side effects happen. So I'd expect the output to be 112 instead.
> 
> Yes, but the sequence point has no effect on when the *second* argument 
> for every call is evaluated.  You seem to forget that.

Victor, this explains why I was confused. I was secretly thinking of the other case

cout << "good " << "news " << "everybody\n";

where the compiler can also evaluate the strings in any order, but this works in that case because they are all constant, so every possible ordering gives the same return value. 

Thanks to everybody who responded.

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Help with post-increment and sequence points laird@lbreyer.com - 2011-10-20 00:23 -0700
  Re: Help with post-increment and sequence points Leigh Johnston <leigh@i42.co.uk> - 2011-10-20 12:57 +0100
  Re: Help with post-increment and sequence points softwareEngineer <ovNOSPAM@NOSPAMlibero.it> - 2011-10-20 14:16 +0200
  Re: Help with post-increment and sequence points Victor Bazarov <v.bazarov@comcast.invalid> - 2011-10-20 08:26 -0400
    Re: Help with post-increment and sequence points Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-10-20 06:06 -0700
      Re: Help with post-increment and sequence points Victor Bazarov <v.bazarov@comcast.invalid> - 2011-10-20 09:50 -0400
    Re: Help with post-increment and sequence points laird@lbreyer.com - 2011-10-20 14:16 -0700
  Re: Help with post-increment and sequence points Markus Wichmann <nullplan@gmx.net> - 2011-10-20 18:09 +0200

csiph-web