Article View: comp.std.c++
Article #3882Re: constness of private members and methods
From: Martin D Kealey
Date: Mon, 01 Apr 1996 18:39
Date: Mon, 01 Apr 1996 18:39
41 lines
2631 bytes
2631 bytes
> Being const means only that the current function won't change the
> object, not that the object itself won't change during the function.
> It could change as the result of a side effect of another function
> called within the current one.
A non-const object can be changed any time its name or a non-const
pointer is in scope, through the name or pointer; this behaviour
is not surprising. But as I understand it, there is no
dispensation to modify it through a const-pointer, which includes
"this".
> Thus unless only inline or other internally known functions are
> called, no additional optimizations are possible.
True, but only for the reason above, which is the same reason you
can't optimise away function calls in general.
What are needed (to allow some function calls to be optimised
away) are two new keywords:
* "clean" which guarantees that the function doesn't modify
objects that can only be reached as or through names
in an outer scope - and in turn will not call any non-clean
functions; and
* "pure" which guarantees that the function does not depend on
the value of any outer scope object - and in turn will not
call any non-pure function;
To be fully useful, a function would be declared with both of
these attibutes and with all pointer or reference parameters
(including "this") declared "const".
Anyone care to put this forward, or has it been discussed before?
---
[ 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
]
Technical Details
Message-ID:
<m0u3992-000GcEC@7.kurahaupo.gen.nz>Path:
arc1-ca.pugleaf.net!chronicle.mti.sgi.com!austernShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!chronicle.mti.sgi.com!austern From: martin@kcbbs.gen.nz (Martin D Kealey) Newsgroups: comp.std.c++ Subject: Re: constness of private members and methods Date: 01 Apr 1996 10:39:46 PST Organization: - Approved: austern@isolde.mti.sgi.com Message-ID: <m0u3992-000GcEC@7.kurahaupo.gen.nz> NNTP-Posting-Host: isolde.mti.sgi.com Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Original-Date: Sun, 31 Mar 1996 10:29:15 +1200 (NZST) In-Reply-To: <4j7tfi$1npo@mule1.mindspring.com> from "Andrew Bell" at Mar 26, 96 07:19:43 am X-Mailer: ELM [version 2.4 PL24] X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBVAwUBMWAi80y4NqrwXLNJAQH8nwH+OKO96ZsqsvD/BJkwYiVkBHP7YktjPqvR 5pts1Q0yPxOjq5ZM6UVnMARUe2wohkJzNEUffemAeV/D6bVBpIjyEg== =xtmN Originator: austern@isolde.mti.sgi.com