Content deleted Content added
No edit summary |
|||
Line 1:
In [[computer science]], '''const-correctness''' is the form of program correctness that deals with the proper declaration of objects as [[mutable object|mutable]] or [[immutable object|immutable]]. The term is mostly used in a [[C programming language|C]] or [[C Plus Plus|C++]] context, and takes its name from the <code>const</code> keyword in those languages.
The idea of const-ness does not imply that the variable as it is stored in the [[computer]]'s [[computer storage|memory]] is unwriteable. Rather, <code>const</code>-ness is a [[compile-time]] construct that indicates what a programmer ''may'' do, not necessarily what he or she ''can'' do.
In addition, a [[class method]] can be declared as <code>const</code>, indicating that calling that method does not change the object. Such <code>const</code> methods can only call other <code>const</code> methods but cannot assign [[field (computer science)|member variables]]. (In C++, a member variable can be declared as <code>mutable</code>, indicating that a <code>const</code> method can change its value. Mutable member variables can be used for [[cache|caching]] and [[reference counting]], where the logical meaning of the object is unchanged, but the object is not physically constant since its bitwise representation may change.)
|