Topic: Order of evaluation for member function calls


Author: James Kanze <james-albert.kanze@vx.cit.alcatel.fr>
Date: 1997/07/07
Raw View
Marcelo Cantos <marcelo@janus.mds.rmit.edu.au> writes:

|>  The standard gives no indication as to order of evaluation of
|>  arguments with respect to the object (or I haven't looked hard enough!
|>  ;-).  For instance:
|>
|>    #include <iostream.h>
|>
|>    class Foo {
|>    public:
|>        void f(int) { }
|>    };
|>
|>    Foo g() { cout << "g() "; return Foo(); }
|>    int h() { cout << "h() "; return 0; }
|>
|>    main() { g().f(h()); cout << endl; }
|>
|>  Should the above code produce:
|>
|>    g() h()
|>
|>  or
|>
|>    h() g()
|>
|>  or is it implementation defined?

Not even implementation defined: unspecified.  Either order is
permitted, the implementation doesn't have to tell you which one it
uses, or even be consistent in its use.

--
James Kanze      home:     kanze@gabi-soft.fr        +33 (0)1 39 55 85 62
                 office:   kanze@vx.cit.alcatel.fr   +33 (0)1 69 63 14 54
GABI Software, Sarl., 22 rue Jacques-Lemercier, F-78000 Versailles France
            -- Conseils en informatique industrielle --
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]





Author: Marcelo Cantos <marcelo@janus.mds.rmit.edu.au>
Date: 1997/07/04
Raw View
The standard gives no indication as to order of evaluation of
arguments with respect to the object (or I haven't looked hard enough!
;-).  For instance:

  #include <iostream.h>

  class Foo {
  public:
      void f(int) { }
  };

  Foo g() { cout << "g() "; return Foo(); }
  int h() { cout << "h() "; return 0; }

  main() { g().f(h()); cout << endl; }

Should the above code produce:

  g() h()

or

  h() g()

or is it implementation defined?  My guess is that the object is just
treated as another parameter (albeit hidden) from the perspective of
argument evaluation order, and hence its evaluation order is
implementation defined.

I would like to be more certain, however.

--
______________________________________________________________________
Marcelo Cantos, Research Assistant       __/_  marcelo@mds.rmit.edu.au
Multimedia Database Systems Group, RMIT   /       _ Tel 61-3-9282-2497
L2/723 Swanston St, Carlton VIC 3053, Aus/ralia ><_>Fax 61-3-9282-2490
Acknowledgements: errors - me; wisdom - God; sponsorship - RMIT
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]