🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #2268

Q: why not a Side effect qualifier ?

#2268
From: Jean-Louis Moser
Date: Fri, 20 Oct 1995 16:40
52 lines
2131 bytes

On october 13, I asked:

|   is A a = 100; equivalent to A a (100); ?

If I well understand the different threads the answer is NO.

   A a = 100 is known as copy initialization and may or not require
   Copy constructor depending on compilers optimizations which can be
   different from a compiler to an other, but without taking in account
   copy constructor side effect.
   
Why C++ methods an functions could not be qualified as having "SideEffect".
This could enable compilers to make more and predictable optimizations.
Suppose this stupid code:

|   #include "A.h"
|   A a;
|   int x = a.val() + a.val();

If this code doesn't know A::val implementation, that is, A interface is
in A.h and A implementation in A.cc, A::val() will be called twice even
A::val() is a const method, because compiler can not see the implementation
of A::val() which can be:

	{return 1;} (no side effect)
or
	{return global_var++;}

The Side Effect property would be inherited by any function or method
which would have in its body a Side Effect function or method. global
or static variable affect, I/O would be Side Effect functions.

what about this ?

jlm

   

   
--
+----------------------------+------------------------------------+
|   Jean-Louis Moser         |    2001 SA                         |
|   tel: 33 (1)46.66.54.54   |    2, rue de la renaissance        |
|   Email: jlm@two-oo-one.fr |    F-92184 Antony Cedex            |
+----------------------------+------------------------------------+

---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID: <JLM.95Oct20114956@ludo.two-oo-one.fr>
Path: arc1-ca.pugleaf.net!128.32.155.1!matt

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!128.32.155.1!matt
From: jlm@two-oo-one.fr (Jean-Louis Moser)
Newsgroups: comp.std.c++
Subject: Q: why not a Side effect qualifier ?
Date: 20 Oct 1995 16:40:34 GMT
Organization: Images 2001 S.A
Approved: matt@physics2.Berkeley.EDU (Matt Austern)
Message-ID: <JLM.95Oct20114956@ludo.two-oo-one.fr>
NNTP-Posting-Host: physics2.berkeley.edu