Knowledge (XXG)

const (computer programming)

Source 📝

4628:"Let me begin by saying that I'm not convinced that even the pre-December qualifiers ('const' and 'volatile') carry their weight; I suspect that what they add to the cost of learning and using the language is not repaid in greater expressiveness. 'Volatile', in particular, is a frill for esoteric applications, and much better expressed by other means. Its chief virtue is that nearly everyone can forget about it. 'Const' is simultaneously more useful and more obtrusive; you can't avoid learning about it, because of its presence in the library interface. Nevertheless, I don't argue for the extirpation of qualifiers, if only because it is too late." 4715:"The declared object is a constant if the reserved word constant appears in the object declaration; the declaration must then include an explicit initialization. The value of a constant cannot be modified after initialization. Formal parameters of mode in of subprograms and entries, and generic formal parameters of mode in, are also constants; a loop parameter is a constant within the corresponding loop; a subcomponent or slice of a constant is a constant." 3043: 3109:
type qualifier causes difficulties when the logic of a function is agnostic to whether its input is constant or not, but returns a value which should be of the same qualified type as an input. In other words, for these functions, if the input is constant (const-qualified), the return value should be
1778:
parameter in pass-by-value (or the pointer itself, in pass-by-reference) does not add anything to the interface (as the value has been copied), but indicates that internally, the function does not modify the local copy of the parameter (it is a single assignment). For this reason, some favor using
1730:
More complicated declarations are encountered when using multidimensional arrays and references (or pointers) to pointers. Although it is sometimes argued that such declarations are confusing and error-prone and that they therefore should be avoided or be replaced by higher-level structures, the
2607:
The C language has a need of a loophole because a certain situation exists. Variables with static storage duration are allowed to be defined with an initial value. However, the initializer can use only constants like string constants and other literals, and is not allowed to use non-constant
4023:
variable that cannot be reassigned nor redeclared. It defines a read-only reference to a variable that cannot be redefined, but in some situations the value of the variable itself may potentially change, such as if the variable refers to an object and a property of it is altered.
3073:
The use of the type system to express constancy leads to various complexities and problems, and has accordingly been criticized and not adopted outside the narrow C family of C, C++, and D. Java and C#, which are heavily influenced by C and C++, both explicitly rejected
509:
makes values "easier to understand, track, and reason about", and it thus increases the readability and comprehensibility of code and makes working in teams and maintaining code simpler because it communicates information about a value's intended use. This can help the
3943:
keyword similar to that of C#: it also declares a compile-time constant rather than forming part of the type. However, in Nim, a constant can be declared from any expression that can be evaluated at compile time. In C#, only C# built-in types can be declared as
1391:
As a final note regarding pointer definitions: always write the pointer symbol (the *) as much as possible to the right. Attaching the pointer symbol to the type is tricky, as it strongly suggests a pointer type, which isn't the case. Here are some examples:
1286:
Although C/C++ allows such definitions (which closely match the English language when reading the definitions from left to right), the compiler still reads the definitions according to the abovementioned procedure: from right to left. But putting
3511:
This allows idiomatic C code but does strip the const qualifier if the input actually was const-qualified, violating type safety. This solution was proposed by Ritchie and subsequently adopted. This difference is one of the failures of
991:
is to read the declaration from right to left. Thus, everything to the left of the star can be identified as the pointed type and everything to the right of the star are the pointer properties. For instance, in our example above,
425:
may indeed change its value while the program is running. A common example are read only registers within embedded systems like the current state of a digital input. The data registers for digital inputs are often declared as
600:
object, on the other hand, can be reassigned to point to another memory location (which should be an object of the same type or of a convertible type), but it cannot be used to modify the memory that it is pointing to. A
2415:
qualifier, making any object modifiable. The necessity of stripping the qualifier arises when using existing code and libraries that cannot be modified but which are not const-correct. For instance, consider this code:
2375:
will be invoked and thus whether or not the caller is given a reference with which he can manipulate or only observe the private data in the object. The two methods technically have different signatures because their
2972:
qualifier when the pointee is not owned by the container, but this strategy would create compatibility issues with existing code. Thus, for historical reasons, this loophole remains open in C and C++.
3468:
However, in C neither of these is possible since C does not have function overloading, and instead, this is handled by having a single function where the input is constant but the output is writable:
3982:(it has no special meaning). The keyword was included as a means for Java compilers to detect and warn about the incorrect usage of C++ keywords. An enhancement request ticket for implementing 1013:
back up to where you began, and read backwards to the left (i.e., until the beginning of the declaration or to the open-parenthesis matching the closing parenthesis found in the previous step)
3249:
the return value should be as well – most simply because it might return exactly the input pointer, if the first character is a match – but on the other hand the return value should not be
3851:"It served two functions: as a way of defining a symbolic constant that obeys scope and type rules (that is, without using a macro) and as a way of deeming an object in memory immutable." 609:
object can also be declared and can neither be used to modify the apointee nor be reassigned to point to another object. The following code illustrates these subtleties:
3891:. Ritchie was not very supportive of these additions, arguing that they did not "carry their weight", but ultimately did not argue for their removal from the standard. 586:
pointer cannot be reassigned to point to a different object from the one it is initially assigned, but it can be used to modify the value that it points to (called the
493:. In these cases, the logical meaning (state) of the object is unchanged, but the object is not physically constant since its bitwise representation may change. 4400: 1294:
what must be constant quickly introduces mismatches between what you intend to write and what the compiler decides you wrote. Consider pointers to pointers:
4269: 2775:
Another loophole applies both to C and C++. Specifically, the languages dictate that member pointers and references are "shallow" with respect to the
4368: 4335: 2983:
object (implying that the containing class cannot be copied by the usual semantics either) or allow other loopholes by permitting the stripping of
1016:
when you've reached the beginning of the declaration you're done. If not, continue at step 2, beyond the closing parenthesis that was matched last.
3922:
Other languages do not follow C/C++ in having constancy part of the type, though they often have superficially similar constructs and may use the
346:
is modifiable or not. This type-checking is primarily of interest in pointers and references – not basic value types like integers – but also for
1800:
approach for user-defined types (structs and classes), which can have methods as well as member data, the programmer may tag instance methods as
505:, and const-correctness dictates that all variables or objects should be declared as such unless they need to be modified. Such proactive use of 4706: 4813: 61: 4451: 3018:
are among these functions. Some implementations of the C++ standard library, such as Microsoft's try to close this loophole by providing two
4823: 4767: 1783:
in parameters only for pass-by-reference, where it changes the contract, but not for pass-by-value, where it exposes the implementation.
4527: 3118:
of these functions differs, it requires two functions (or potentially more, in case of multiple inputs) with the same logic – a form of
1750:
static variable (global variable or static local variable) is a constant, and may be used for data like mathematical constants, such as
1010:
read as far as possible to the right (i.e., until the end of the declaration or to the next closing parenthesis, whichever comes first)
124: 4298: 4236: 2964:
might solely own the pointee. For this reason, Meyers argues that the default for member pointers and references should be "deep"
3881:, was suggested at the December 1987 meeting of the X3J11 committee, but was rejected; its goal was ultimately fulfilled by the 2620:
variable that has static storage duration. By carefully constructing a typecast on the left hand side of a later assignment, a
2404:
There are several loopholes to pure const-correctness in C and C++. They exist primarily for compatibility with existing code.
432: 128: 53: 1817: 351: 69: 45: 3933:
keyword, but with radically different and simpler semantics: it means a compile-time constant, and is not part of the type.
3185:
function does not modify the input string, but the return value is often used by the caller to modify the string, such as:
1525:
Bjarne Stroustrup's FAQ recommends only declaring one variable per line if using the C++ convention, to avoid this issue.
4774: 3513: 2147:
method with the same name (but possibly quite different uses) in a class to accommodate both types of callers. Consider:
1829: 4297:. Vicksburg, Massachusetts, USA: US Army Corps of Engineers Waterways Experiment Station, Major Shared Resource Center. 105: 3974:
as a reserved keyword – i.e., one that cannot be used as variable identifier – but assigns no semantics to it: it is a
3855:
The first use, as a scoped and typed alternative to macros, was analogously fulfilled for function-like macros via the
2636:
variable this way may work as intended, but it causes undefined behavior and seriously contradicts const-correctness:
1813: 457: 136: 109: 4789: 4725: 1808:
qualifier to instance methods thus is an essential feature for const-correctness, and is not available in many other
4390: 3936: 188: 4604: 3133:
function locates a character in a string; formally, it returns a pointer to the first occurrence of the character
2392:
by value, may be overkill in the second method, but the same technique can be used for arbitrary types, as in the
3520: 2995: 2393: 121: 4637: 1731:
procedure described at the top of this section can always be used without introducing ambiguities or confusion.
3540: 472: 132: 97: 89: 4611:", 2003: "X3J11 also introduced a host of smaller additions and adjustments, for example, the type qualifiers 3990:, but was closed in 2005 on the basis that it was impossible to implement in a backwards-compatible fashion. 2787:
members except that member pointees (and referees) are still mutable. To illustrate, consider this C++ code:
481:, indicating that this restriction does not apply to it. In some cases, this can be useful, for example with 3967:, not the type. It has a different object-oriented use for object members, which is the origin of the name. 1858: 471:. This means that non-const functions for this object cannot be called from inside such a function, nor can 335: 4263: 3531:
pointer if one was passed to them and an unqualified pointer if an unqualified pointer was passed to them.
4396: 3987: 3094:
varies significantly, with some projects and organizations using it consistently, and others avoiding it.
530:
qualifier is straightforward. It can go on either side of some types for historical reasons (for example,
4699: 255:
is part of the type, it must match as part of type-checking. For example, the following code is invalid:
4567:, "Extensions of the C Language Type Concept", Bell Labs internal Technical Memorandum, January 5, 1981. 4356: 4323: 4779: 4703: 4661: 3261: 3019: 490: 33: 4676:"Bug ID: JDK-4211070 Java should support const parameters (like C++) for code maintainence [ 4416:) by Walter S. Brainerd, Jeanne C. Adams, Jeanne T. Martin, Brian T. Smith, and Jerrold L. Wagener.) 1003:
A more generic rule that helps you understand complex declarations and definitions works like this:
4818: 4503: 4292:"Cray Fortran Pointers vs. Fortran 90 Pointers and Porting from the Cray C90 to the SGI Origin2000" 4224: 3564: 3119: 1770:
parameter in pass-by-reference means that the referenced value is not modified – it is part of the
515: 347: 327: 73: 4364: 4331: 2991: 1797: 1771: 486: 4147: 562:
is more complicated – either the pointer itself, or the value being pointed to, or both, can be
3078:-style type qualifiers, instead expressing constancy by keywords that apply to the identifier ( 1221:
When reading to the left, it is important that you read the elements from right to left. So an
4597: 4585: 4564: 4447: 4413: 4232: 4033: 3832: 1759: 482: 4516: 3416:
keyword, which acts as a wildcard for const, immutable, or unqualified (variable), yielding:
3265: 2380:" pointers have different types, allowing the compiler to choose the right one. (Returning a 4357:"Appendix C: Fortran 90 Features and Differences > Features > Cray Character Pointers" 4043: 421:
While a constant does not change its value while the program is running, an object declared
2979:-correct interface, but such classes either do not support the usual copy semantics from a 4710: 4002: 2584:
results in undefined behavior according to the ISO C++ Standard. In the example above, if
1809: 1743: 379: 363: 81: 64:
of languages differs from similar constructs in other languages in that it is part of the
4799:"Const and Invariant" from D programming language specification, version 2 (experimental) 4648: 4463: 4291: 4544: 4066:
is part of the outermost derived type in a declaration; pointers complicate discussion.
3903: 3836: 3115: 501:
In C, C++, and D, all data types, including those defined by the user, can be declared
477: 402: 339: 41: 3042: 4807: 4793: 4608: 4123: 2952:
is constant, which makes all of its members constant, the pointee accessible through
1862:" pointer, which is an implicit argument passed to all instance methods. Thus having 988: 833: 367: 359: 77: 4426: 1746:
or automatic, including global or local). The interpretation varies between uses. A
4439: 387: 343: 85: 4675: 4484: 4324:"Appendix C: Fortran 90 Features and Differences > Features > Cray Pointers" 4171: 3125:
This problem arises even for simple functions in the C standard library, notably
139:. This basic use – to declare constants – has parallels in many other languages. 17: 4784: 4756: 4581: 4220: 4075:
Note that pointer declaration syntax conventions differ between C and C++: in C
4020: 2975:
The latter loophole can be closed by using a class to hide the pointer behind a
828:
Following usual C convention for declarations, declaration follows use, and the
436:. The content of these registers may change without the program doing anything ( 4798: 52:) that indicates that the data is read-only. While this can be used to declare 4012: 3257:, since the caller may wish to use the pointer to modify the original string. 2581: 101: 4601: 2956:
is still modifiable, though this may not be desirable from the standpoint of
996:
can be read as a writable pointer that refers to a non-writable integer, and
3129:; this observation is credited by Ritchie to Tom Plum in the mid 1980s. The 2608:
elements like variable names, whether the initializer elements are declared
2100:// Error! Set() is a non-const method and constC is a const-qualified object 1825: 1821: 1528:
The same considerations apply to defining references and rvalue references:
49: 3963:, which can be applied to local "variable" declarations and applies to the 378:
The idea of const-ness does not imply that the variable as it is stored in
2677://initial value depends on const bufferSize, can't be initialized here 514:
as well as the developer when reasoning about code. It can also enable an
4038: 3883: 1000:
can be read as a non-writable pointer that refers to a writable integer.
511: 3948:; user-defined types, including classes, structs, and arrays, cannot be 3547:
keyword denotes data that cannot be modified through any reference. The
1856:
modifier on an instance method applies to the object pointed to by the "
3926:
keyword. Typically this is only used for constants (constant objects).
3245:(since it is not modified by the function), and if the input string is 588: 566:. Further, the syntax can be confusing. A pointer can be declared as a 440:) but it would be ill-formed for the program to attempt write to them ( 4248: 2628:
attribute and 'initializing' it with non-constant elements like other
1762:
is happening, though a different value may be used each time, such as
1240:
keyword to be placed to the left of the type. Here are some examples:
3994: 3870: 3014: 3008: 251:
declares a constant pointer to a variable integer. Secondly, because
187:
is part of the type, as if it were parsed "(int const) x" – while in
142:
However, unlike in other languages, in the C family of languages the
4262:"5.1. Extensions implemented in GNU Fortran: 5.1.16 Cray pointers". 3268:, resulting in two functions, so that the return value has the same 2132:", indicating that the method cannot modify its object through the " 4517:"WG14-N3020 : Qualifier-preserving standard library functions" 3840: 93: 2612:
or not, or whether the static duration variable is being declared
3869:
was then adopted in C as part of standardization, and appears in
2576:
However, any attempt to modify an object that is itself declared
987:
Following C++ convention of analyzing the type, not the value, a
398:
do. Note, however, that in the case of predefined data (such as
3873:(and subsequent versions) along with the other type qualifier, 3551:
keyword denotes a non-mutable view of mutable data. Unlike C++
452:
In addition, a (non-static) member-function can be declared as
4761: 4752: 4092:
Idiomatic D code would use an array here instead of a pointer.
3888: 3037: 1754:– realistically longer, or overall compile-time parameters. A 1742:
can be declared both on function parameters and on variables (
342:
whether they modify their arguments or not, and whether their
239:
can be applied to parts of a more complex type – for example,
3114:-qualified), the return value should be as well. Because the 2779:-ness of their owners – that is, a containing object that is 1866:
methods is a way to apply const-correctness to the implicit "
1804:
if they don't modify the object's data members. Applying the
864:
to its right. The C++ convention is instead to associate the
3527:
and the other functions affected by the issue will return a
3523:, this problem is solved with the use of generic functions. 2421:// Prototype for a function which we cannot change but which 1007:
find the identifier whose declaration you want to understand
3863:
notation, were suggested by Dennis Ritchie and so adopted.
2624:
variable can be written to, effectively stripping away the
2588:
references a global, local, or member variable declared as
370:(C++ and D are either call-by-value or call-by-reference). 3815:// Won't compile. foo.next is of type immutable(Foo). 3722:// Error: Cannot create a mutable view of immutable data. 2359:// Error! (Calls: int const & MyArray::Get(int) const) 1758:
automatic variable (non-static local variable) means that
900:" (the pointer is a pointer to a constant integer). Thus: 592:). Reference variables in C++ are an alternate syntax for 475:
be modified. In C++, a member variable can be declared as
4485:"Dennis Ritchie: Why I do not like X3J11 type qualifiers" 3653:// Error: all views of immutable data must be immutable. 243:
declares a constant pointer to a constant integer, while
4005:
and loop parameters being implicitly constant. Here the
3997:
independently had the notion of a constant object and a
3704:// Works. immutable is implicitly convertible to const. 2371:-ness of the calling object determines which version of 1386:// a constant pointer to pointers to constant int values 4506:, 8.8: Propagating a Qualifier from Parameter to Result 3054: 247:
declares a variable pointer to a constant integer, and
68:, and thus has complicated behavior when combined with 4105:
type constructor, but this is related to use cases of
2909:// Error: s is const, so ptr is a const pointer to int 570:
pointer to writable value, or a writable pointer to a
2616:
or not. There is a non-portable way to initialize a
2933:// OK: the data pointed to by ptr is always mutable, 2407:
The first, which applies only to C++, is the use of
1368:// (ptr, the identifier, being const makes no sense) 974:// constPtrToConst is a constant pointer and points 832:in a pointer is written on the pointer, indicating 192: 155: 27:
Type qualifier denoting the data as being read-only
2987:-ness through inadvertent or intentional copying. 2936:// even though this is sometimes not desirable 1472:// but b is a mere int 953:// constPtr is a constant (int *: integer pointer) 80:. In other languages, the data is not in a single 3141:, and in classic C (K&R C) its prototype is: 2424:// we know does not modify the pointee passed in. 935:// *ptrToConst is a constant (int: integer value) 1638:// ERROR: as references can't change anyway. 1350:// (not a constant pointer to a pointer to ints) 1329:// (not a pointer to a constant pointer to ints) 1281://identical to: int const *const constPtrToConst 558:For pointer and reference types, the meaning of 526:For simple non-pointer data types, applying the 4619:, and slightly different type promotion rules." 4412:(NB. Derived from "FORTRAN 90 HANDBOOK" (1992, 3683:// No mutable reference to nums may be created. 3002:pointer to a character string and return a non- 2764:// warning: might work, but not guaranteed by C 2600:really does not modify the value pointed to by 1326:// a pointer to a pointer to constant int value 4009:is a property of the object, not of the type. 1870:" pointer argument just like other arguments. 3978:(it cannot be used in identifiers) but not a 1347:// a pointer to a const pointer to int values 88:for each use. Languages which use it include 8: 3543:, two keywords relating to const exist. The 3351:These can in turn be defined by a template: 1683:// rref is an rvalue reference, but value is 4662:"Java Language Specification Third Edition" 4577: 4575: 4573: 4392:Fortran Language Reference Manual, Volume 1 3906:) and added two further type constructors, 3110:as well, but if the input is variable (not 2885:// Error: s is const, so val is a const int 2411:, which allows the programmer to strip the 2329:// OK! (Calls: int & MyArray::Get(int)) 1608:// ref2 is a reference, but ref3 isn't: 800:// Error! Cannot modify the pointed to data 734:// Error! Cannot modify the pointed to data 390:construct that indicates what a programmer 338:, where functions specify as part of their 3818:// foo.next.num is of type immutable(int). 3090:in C#). Even within C and C++, the use of 1611:// ref3 is a constant int initialized with 1496:// UGLY: both a and b are pointers to ints 4427:"Stroustrup: C++ Style and Technique FAQ" 4290:Fahey, Mark R.; Nagle, Dan (1999-04-19). 2592:, or an object allocated on the heap via 1365:// a constant pointer to pointers to ints 4660:Gosling, James; Joy, Bill; Steele, Guy. 3970:The Java language specification regards 3728:Example of transitive or deep const in D 2139:Often the programmer will supply both a 1022: 550:) generates a warning but not an error. 4496: 4494: 4139: 4055: 3847:. As to motivation, Stroustrup writes: 3632:// bar is a const view of mutable data. 354:. It is concealed by the fact that the 212:declares a constant (a kind of object) 4399:1999 . Document Number: 007-3692-004. 4194:in a member function whose type has a 3237:Thus on the one hand the input string 3006:pointer to a part of the same string. 2968:-ness, which could be overridden by a 2296:// Get a reference to an array element 1260://identical to: int const *ptrToConst, 235:This has two subtle results. Firstly, 4545:"const(FAQ) – D Programming Language" 4446:. pp. 21–23. Boston: Addison Wesley. 4148:"Constant items – The Rust Reference" 3843:, in 1981, and was originally called 1950:// Note the lack of "const" 7: 4249:"Why is the kfree() argument const?" 3859:keyword. Constant pointers, and the 2632:variables and such. Writing into a 326:integer. This matching is a form of 127:, it indicates that the object is a 4768:The C++ FAQ Lite: Const correctness 3587:Example of const vs. immutable in D 3567:, and anything reachable through a 2299:// and modify its referenced value. 1848:methods can only be invoked by non- 815:// Error! Cannot modify the pointer 782:// Error! Cannot modify the pointer 767:// OK: modifies the pointed to data 701:// OK: modifies the pointed to data 2990:Finally, several functions in the 2388:, instead of merely returning the 1796:In order to take advantage of the 836:. For example, in the declaration 538:). On some implementations, using 463:inside such a function is of type 25: 4602:The Development of the C Language 4231:. p. 30. Boston: Addison Wesley. 3898:from C++, where it is known as a 2994:violate const-correctness before 2108:In the above code, the implicit " 1914:// Note the "const" tag 1311:// a pointer to a pointer to ints 1159:a function expecting a double ... 518:to generate more efficient code. 4777:" from the free electronic book 4533:from the original on 2022-10-13. 3041: 4464:"strchr, wcschr, _mbschr (CRT)" 4403:from the original on 2022-12-23 4371:from the original on 2022-12-23 4338:from the original on 2021-09-21 4304:from the original on 2022-12-23 4272:from the original on 2022-12-21 4122:The Ada standard calls this a " 3914:, to handle related use cases. 3253:if the original string was not 3022:versions of some functions: a " 2511:// Error! Drops const qualifier 1236:In some cases C/C++ allows the 1182:returning a constant pointer to 892:" (the value is constant), or " 4126:"; see that article for usage. 3272:-qualified type as the input: 3264:, typically implemented via a 2596:, the code is only correct if 2400:Loopholes to const-correctness 2079:// Ok: nonConstC is modifiable 394:do, not necessarily what they 1: 4814:C programming language family 4790:"Here A Const, There A Const" 3412:In D this is handled via the 1469:// a is a pointer to an int, 1116:function expecting an int ... 358:can often be omitted, due to 135:may not be changed, unlike a 4444:Effective C++, Third Edition 4824:Programming language topics 4501:The D Programming Language, 4019:declaration that defines a 1764:int const x_squared = x * x 1424:// a is a pointer to an int 848:, while the reference form 749:// OK: modifies the pointer 716:// OK: modifies the pointer 467:rather than merely of type 350:or templated types such as 4840: 4704:3.2.1. Object Declarations 4582:Sibling Rivalry: C and C++ 4079:is standard, while in C++ 3986:correctness exists in the 3514:compatibility of C and C++ 1873:This example illustrates: 1830:Managed Extensions for C++ 1136:returning a pointer to ... 417:Distinction from constants 4709:October 20, 2014, at the 4638:Nim Manual: Const section 4389:"Chapter 4. Data Types". 3894:D subsequently inherited 2394:Standard Template Library 1836:methods can be called by 1752:double const PI = 3.14159 1070: 1028: 1025: 596:pointers. A pointer to a 4762:"Constant Optimization?" 4265:The GNU Fortran Compiler 3731: 3590: 3470: 3418: 3353: 3274: 3260:In C++ this is done via 3187: 3143: 2789: 2638: 2418: 2149: 1875: 1735:Parameters and variables 1530: 1394: 1296: 1242: 1206: 1192: 1167: 1144: 1124: 1101: 1081: 1029: 902: 840:, the dereferenced form 611: 334:. This allows a form of 310:because the argument to 257: 4251:. lkml.org. 2013-01-12. 3877:. A further qualifier, 1231:const pointer to an int 917:// *ptr is an int value 554:Pointers and references 382:is unwritable. Rather, 336:programming by contract 4397:Silicon Graphics, Inc. 4101:D also introduced the 3988:Java Community Process 3541:D programming language 2710:defaultTextBoxLocation 1227:pointer to a const int 977:// to a constant value 882:int const * ptrToConst 228:, but not part of the 3839:, the predecessor to 3026:" version and a "non- 2960:-correctness because 2058:// Ok: Get() is const 1020:Here is an example: 884:can thus be read as " 868:with the type, as in 542:twice (for instance, 536:char const foo = 'a'; 532:const char foo = 'a'; 154:. For example, in C, 34:programming languages 4649:const (C# Reference) 4466:. Msdn.microsoft.com 4361:Fortran User's Guide 4328:Fortran User's Guide 4229:C++ Coding Standards 3539:In Version 2 of the 3262:function overloading 2944:Although the object 491:data synchronization 456:. In this case, the 348:composite data types 241:int const * const x; 74:composite data types 4753:"Const-Correctness" 4504:Andrei Alexandrescu 4225:Andrei Alexandrescu 4198:and whose class is 4196:cv-qualifier-seq cv 3955:Java does not have 3120:generic programming 2998:, as they accept a 1844:objects alike, non- 1164:Find the matching ( 1121:Find the matching ( 1073:(reading downwards) 852:is a pointer to an 516:optimizing compiler 465:object_type const * 328:program correctness 175:declares an object 120:When applied in an 4775:Value substitution 4607:July 15, 2012, at 4365:Oracle Corporation 4332:Oracle Corporation 4180:Draft C++ Standard 4062:Formally when the 3831:was introduced by 3611:// foo is mutable. 3053:. You can help by 2992:C standard library 2737:userTextBufferSize 2698:defaultTextBoxType 2671:userTextBufferSize 2547:// Strip qualifier 1812:languages such as 1798:design by contract 1614:// var's value 1026:Part of expression 487:reference counting 330:, and is known as 150:, not part of the 4770:by Marshall Cline 4598:Dennis M. Ritchie 4586:Bjarne Stroustrup 4565:Bjarne Stroustrup 4547:. Digitalmars.com 4452:978-0-321-33487-9 4414:McGraw-Hill, Inc. 4152:doc.rust-lang.org 4034:Single assignment 3993:The contemporary 3959:– it instead has 3833:Bjarne Stroustrup 3071: 3070: 1760:single assignment 1219: 1218: 1098:Read to the right 876:as modifying the 534:is equivalent to 522:Simple data types 332:const-correctness 18:Const correctness 16:(Redirected from 4831: 4740: 4739: 4737: 4736: 4722: 4716: 4697: 4691: 4690: 4688: 4687: 4672: 4666: 4665: 4657: 4651: 4646: 4640: 4635: 4629: 4626: 4620: 4595: 4589: 4579: 4568: 4562: 4556: 4555: 4553: 4552: 4541: 4535: 4534: 4532: 4521: 4513: 4507: 4498: 4489: 4488: 4481: 4475: 4474: 4472: 4471: 4460: 4454: 4437: 4431: 4430: 4423: 4417: 4411: 4409: 4408: 4386: 4380: 4379: 4377: 4376: 4353: 4347: 4346: 4344: 4343: 4320: 4314: 4312: 4310: 4309: 4303: 4296: 4287: 4281: 4280: 4278: 4277: 4259: 4253: 4252: 4245: 4239: 4218: 4212: 4211: 4208: 4201: 4193: 4187: 4186: 4175: 4168: 4162: 4161: 4159: 4158: 4144: 4127: 4120: 4114: 4112: 4108: 4104: 4099: 4093: 4090: 4084: 4082: 4078: 4073: 4067: 4065: 4060: 4044:Pointer aliasing 4018: 4008: 4003:input parameters 4000: 3985: 3973: 3962: 3958: 3951: 3947: 3942: 3932: 3925: 3913: 3909: 3900:type constructor 3897: 3886: 3880: 3876: 3868: 3862: 3858: 3846: 3830: 3819: 3816: 3813: 3810: 3807: 3804: 3801: 3798: 3795: 3792: 3789: 3786: 3783: 3780: 3777: 3774: 3771: 3768: 3765: 3762: 3759: 3756: 3753: 3750: 3747: 3744: 3741: 3738: 3735: 3723: 3720: 3717: 3714: 3711: 3708: 3705: 3702: 3699: 3696: 3693: 3690: 3687: 3684: 3681: 3678: 3675: 3672: 3669: 3666: 3663: 3660: 3657: 3654: 3651: 3648: 3645: 3642: 3639: 3636: 3633: 3630: 3627: 3624: 3621: 3618: 3615: 3612: 3609: 3606: 3603: 3600: 3597: 3594: 3582: 3578: 3574: 3570: 3562: 3558: 3554: 3550: 3546: 3530: 3526: 3507: 3504: 3501: 3498: 3495: 3492: 3489: 3486: 3483: 3480: 3477: 3474: 3464: 3461: 3458: 3455: 3452: 3449: 3446: 3443: 3440: 3437: 3434: 3431: 3428: 3425: 3422: 3415: 3408: 3405: 3402: 3399: 3396: 3393: 3390: 3387: 3384: 3381: 3378: 3375: 3372: 3369: 3366: 3363: 3360: 3357: 3347: 3344: 3341: 3338: 3335: 3332: 3329: 3326: 3323: 3320: 3317: 3314: 3311: 3308: 3305: 3302: 3299: 3296: 3293: 3290: 3287: 3284: 3281: 3278: 3271: 3256: 3252: 3248: 3244: 3233: 3230: 3227: 3224: 3221: 3218: 3215: 3212: 3209: 3206: 3203: 3200: 3197: 3194: 3191: 3184: 3177: 3174: 3171: 3168: 3165: 3162: 3159: 3156: 3153: 3150: 3147: 3140: 3136: 3132: 3128: 3113: 3108: 3100: 3093: 3089: 3085: 3081: 3077: 3066: 3063: 3045: 3038: 3029: 3025: 3017: 3011: 3005: 3001: 2986: 2982: 2978: 2971: 2967: 2963: 2959: 2955: 2951: 2947: 2940: 2937: 2934: 2931: 2928: 2925: 2922: 2919: 2916: 2913: 2910: 2907: 2904: 2901: 2898: 2895: 2892: 2889: 2886: 2883: 2880: 2877: 2874: 2871: 2868: 2865: 2862: 2859: 2856: 2853: 2850: 2847: 2844: 2841: 2838: 2835: 2832: 2829: 2826: 2823: 2820: 2817: 2814: 2811: 2808: 2805: 2802: 2799: 2796: 2793: 2786: 2782: 2778: 2771: 2768: 2765: 2762: 2759: 2756: 2753: 2750: 2747: 2744: 2741: 2738: 2735: 2732: 2729: 2726: 2723: 2720: 2717: 2714: 2711: 2708: 2705: 2702: 2699: 2696: 2693: 2690: 2687: 2686:setupUserTextBox 2684: 2681: 2678: 2675: 2672: 2669: 2666: 2663: 2660: 2657: 2654: 2651: 2648: 2645: 2642: 2635: 2631: 2627: 2623: 2619: 2615: 2611: 2603: 2599: 2595: 2591: 2587: 2579: 2572: 2569: 2566: 2563: 2560: 2557: 2554: 2551: 2548: 2545: 2542: 2539: 2536: 2533: 2530: 2527: 2524: 2521: 2518: 2515: 2512: 2509: 2506: 2503: 2500: 2497: 2494: 2491: 2488: 2485: 2482: 2479: 2476: 2473: 2470: 2467: 2464: 2461: 2458: 2455: 2452: 2449: 2446: 2443: 2440: 2437: 2434: 2431: 2428: 2425: 2422: 2414: 2410: 2391: 2387: 2384:reference to an 2383: 2379: 2374: 2370: 2363: 2360: 2357: 2354: 2351: 2348: 2345: 2342: 2339: 2336: 2333: 2330: 2327: 2324: 2321: 2318: 2315: 2312: 2309: 2306: 2303: 2300: 2297: 2294: 2291: 2288: 2285: 2282: 2279: 2276: 2273: 2270: 2267: 2264: 2261: 2258: 2255: 2252: 2249: 2246: 2243: 2240: 2237: 2234: 2231: 2228: 2225: 2222: 2219: 2216: 2213: 2210: 2207: 2204: 2201: 2198: 2195: 2192: 2189: 2186: 2183: 2180: 2177: 2174: 2171: 2168: 2165: 2162: 2159: 2156: 2153: 2146: 2142: 2135: 2131: 2127: 2123: 2120:"; whereas the " 2119: 2115: 2111: 2104: 2101: 2098: 2095: 2092: 2089: 2086: 2083: 2080: 2077: 2074: 2071: 2068: 2065: 2062: 2059: 2056: 2053: 2050: 2047: 2044: 2041: 2038: 2035: 2032: 2029: 2026: 2023: 2020: 2017: 2014: 2011: 2008: 2005: 2002: 1999: 1996: 1993: 1990: 1987: 1984: 1981: 1978: 1975: 1972: 1969: 1966: 1963: 1960: 1957: 1954: 1951: 1948: 1945: 1942: 1939: 1936: 1933: 1930: 1927: 1924: 1921: 1918: 1915: 1912: 1909: 1906: 1903: 1900: 1897: 1894: 1891: 1888: 1885: 1882: 1879: 1869: 1865: 1861: 1855: 1851: 1847: 1843: 1839: 1835: 1807: 1803: 1782: 1777: 1769: 1765: 1757: 1753: 1749: 1741: 1726: 1723: 1720: 1717: 1714: 1711: 1708: 1705: 1702: 1699: 1696: 1693: 1690: 1687: 1684: 1681: 1678: 1675: 1672: 1669: 1666: 1663: 1660: 1657: 1654: 1651: 1648: 1645: 1642: 1639: 1636: 1633: 1630: 1627: 1624: 1621: 1618: 1615: 1612: 1609: 1606: 1603: 1600: 1597: 1594: 1591: 1588: 1585: 1582: 1579: 1576: 1573: 1570: 1567: 1564: 1561: 1558: 1555: 1552: 1549: 1546: 1543: 1540: 1537: 1534: 1521: 1518: 1515: 1512: 1509: 1506: 1503: 1500: 1497: 1494: 1491: 1488: 1485: 1482: 1479: 1476: 1473: 1470: 1467: 1464: 1461: 1458: 1455: 1452: 1449: 1446: 1443: 1440: 1437: 1434: 1431: 1428: 1425: 1422: 1419: 1416: 1413: 1410: 1407: 1404: 1401: 1398: 1387: 1384: 1381: 1378: 1375: 1372: 1369: 1366: 1363: 1360: 1357: 1354: 1351: 1348: 1345: 1342: 1339: 1336: 1333: 1330: 1327: 1324: 1321: 1318: 1315: 1312: 1309: 1306: 1303: 1300: 1290: 1282: 1279: 1276: 1273: 1270: 1267: 1264: 1261: 1258: 1255: 1252: 1249: 1246: 1239: 1224: 1210: 1203:Read to the left 1198:blocks of 10 ... 1184:a pointer to ... 1177: 1174: 1171: 1154: 1151: 1148: 1131: 1128: 1111: 1108: 1105: 1092: 1085: 1066: 1063: 1060: 1057: 1054: 1051: 1048: 1045: 1042: 1039: 1036: 1033: 1023: 999: 995: 978: 975: 972: 969: 966: 963: 960: 957: 954: 951: 948: 945: 942: 939: 936: 933: 930: 927: 924: 921: 918: 915: 912: 909: 906: 899: 895: 891: 887: 883: 875: 871: 867: 859: 855: 851: 847: 843: 839: 831: 819: 816: 813: 810: 807: 804: 801: 798: 795: 792: 789: 786: 783: 780: 777: 774: 771: 768: 765: 762: 759: 756: 753: 750: 747: 744: 741: 738: 735: 732: 729: 726: 723: 720: 717: 714: 711: 708: 705: 702: 699: 696: 693: 690: 687: 684: 681: 678: 675: 672: 669: 666: 663: 660: 657: 654: 651: 648: 645: 642: 639: 636: 633: 630: 627: 624: 621: 618: 615: 608: 604: 599: 595: 585: 581: 577: 573: 569: 565: 561: 549: 548:char const const 545: 544:const char const 541: 537: 533: 529: 508: 504: 480: 473:member variables 470: 466: 460: 455: 443: 439: 435: 429: 424: 408: 401: 385: 357: 321: 313: 306: 303: 300: 297: 294: 291: 288: 285: 282: 279: 276: 273: 270: 267: 264: 261: 254: 250: 246: 242: 238: 223: 219: 215: 211: 210: 207: 204: 201: 198: 195: 186: 182: 178: 174: 173: 170: 167: 164: 161: 158: 145: 84:, but copied at 59: 21: 4839: 4838: 4834: 4833: 4832: 4830: 4829: 4828: 4804: 4803: 4780:Thinking in C++ 4749: 4744: 4743: 4734: 4732: 4724: 4723: 4719: 4714: 4711:Wayback Machine 4698: 4694: 4685: 4683: 4674: 4673: 4669: 4659: 4658: 4654: 4647: 4643: 4636: 4632: 4627: 4623: 4596: 4592: 4580: 4571: 4563: 4559: 4550: 4548: 4543: 4542: 4538: 4530: 4519: 4515: 4514: 4510: 4499: 4492: 4483: 4482: 4478: 4469: 4467: 4462: 4461: 4457: 4438: 4434: 4425: 4424: 4420: 4406: 4404: 4395:. Vol. 1. 4388: 4387: 4383: 4374: 4372: 4355: 4354: 4350: 4341: 4339: 4322: 4321: 4317: 4307: 4305: 4301: 4294: 4289: 4288: 4284: 4275: 4273: 4261: 4260: 4256: 4247: 4246: 4242: 4219: 4215: 4206: 4202:is "pointer to 4199: 4191: 4184: 4182: 4173: 4170: 4169: 4165: 4156: 4154: 4146: 4145: 4141: 4136: 4131: 4130: 4121: 4117: 4110: 4106: 4102: 4100: 4096: 4091: 4087: 4080: 4076: 4074: 4070: 4063: 4061: 4057: 4052: 4030: 4016: 4006: 3998: 3983: 3971: 3960: 3956: 3949: 3945: 3940: 3930: 3923: 3920: 3918:Other languages 3911: 3907: 3895: 3882: 3878: 3874: 3866: 3860: 3856: 3844: 3828: 3826: 3821: 3820: 3817: 3814: 3811: 3808: 3805: 3802: 3799: 3796: 3793: 3790: 3787: 3784: 3781: 3778: 3775: 3772: 3769: 3766: 3763: 3760: 3757: 3754: 3751: 3748: 3745: 3742: 3739: 3736: 3733: 3725: 3724: 3721: 3718: 3715: 3712: 3709: 3706: 3703: 3700: 3697: 3694: 3691: 3688: 3685: 3682: 3679: 3676: 3673: 3670: 3667: 3664: 3661: 3658: 3655: 3652: 3649: 3646: 3643: 3640: 3637: 3634: 3631: 3628: 3625: 3622: 3619: 3616: 3613: 3610: 3607: 3604: 3601: 3598: 3595: 3592: 3580: 3576: 3572: 3568: 3560: 3556: 3552: 3548: 3544: 3537: 3528: 3524: 3509: 3508: 3505: 3502: 3499: 3496: 3493: 3490: 3487: 3484: 3481: 3478: 3475: 3472: 3466: 3465: 3462: 3459: 3456: 3453: 3450: 3447: 3444: 3441: 3438: 3435: 3432: 3429: 3426: 3423: 3420: 3413: 3410: 3409: 3406: 3403: 3400: 3397: 3394: 3391: 3388: 3385: 3382: 3379: 3376: 3373: 3370: 3367: 3364: 3361: 3358: 3355: 3349: 3348: 3345: 3342: 3339: 3336: 3333: 3330: 3327: 3324: 3321: 3318: 3315: 3312: 3309: 3306: 3303: 3300: 3297: 3294: 3291: 3288: 3285: 3282: 3279: 3276: 3269: 3254: 3250: 3246: 3242: 3235: 3234: 3231: 3228: 3225: 3222: 3219: 3216: 3213: 3210: 3207: 3204: 3201: 3198: 3195: 3192: 3189: 3182: 3179: 3178: 3175: 3172: 3169: 3166: 3163: 3160: 3157: 3154: 3151: 3148: 3145: 3138: 3134: 3130: 3126: 3111: 3106: 3103: 3098: 3091: 3087: 3083: 3079: 3075: 3067: 3061: 3058: 3051:needs expansion 3036: 3027: 3023: 3013: 3007: 3003: 2999: 2984: 2980: 2976: 2969: 2965: 2961: 2957: 2953: 2949: 2945: 2942: 2941: 2938: 2935: 2932: 2929: 2926: 2923: 2920: 2917: 2914: 2911: 2908: 2905: 2902: 2899: 2896: 2893: 2890: 2887: 2884: 2881: 2878: 2875: 2872: 2869: 2866: 2863: 2860: 2857: 2854: 2851: 2848: 2845: 2842: 2839: 2836: 2833: 2830: 2827: 2824: 2821: 2818: 2815: 2812: 2809: 2806: 2803: 2800: 2797: 2794: 2791: 2784: 2780: 2776: 2773: 2772: 2769: 2766: 2763: 2760: 2758:textBoxControls 2757: 2754: 2751: 2748: 2745: 2742: 2739: 2736: 2733: 2730: 2727: 2724: 2721: 2718: 2715: 2712: 2709: 2706: 2703: 2700: 2697: 2694: 2691: 2688: 2685: 2682: 2679: 2676: 2673: 2670: 2667: 2664: 2661: 2658: 2655: 2652: 2649: 2646: 2643: 2640: 2633: 2629: 2625: 2621: 2617: 2613: 2609: 2601: 2597: 2593: 2589: 2585: 2577: 2574: 2573: 2570: 2567: 2564: 2561: 2558: 2555: 2552: 2549: 2546: 2543: 2540: 2537: 2534: 2531: 2528: 2525: 2522: 2519: 2516: 2513: 2510: 2507: 2504: 2501: 2498: 2495: 2492: 2489: 2486: 2483: 2480: 2477: 2474: 2471: 2468: 2465: 2462: 2460:CallLibraryFunc 2459: 2456: 2453: 2450: 2447: 2444: 2441: 2438: 2435: 2432: 2429: 2426: 2423: 2420: 2412: 2408: 2402: 2389: 2385: 2381: 2377: 2372: 2368: 2365: 2364: 2361: 2358: 2355: 2352: 2349: 2346: 2343: 2340: 2337: 2334: 2331: 2328: 2325: 2322: 2319: 2316: 2313: 2310: 2307: 2304: 2301: 2298: 2295: 2292: 2289: 2286: 2283: 2280: 2277: 2274: 2271: 2268: 2265: 2262: 2259: 2256: 2253: 2250: 2247: 2244: 2241: 2238: 2235: 2232: 2229: 2226: 2223: 2220: 2217: 2214: 2211: 2208: 2205: 2202: 2199: 2196: 2193: 2190: 2187: 2184: 2181: 2178: 2175: 2172: 2169: 2166: 2163: 2160: 2157: 2154: 2151: 2144: 2140: 2133: 2129: 2125: 2121: 2117: 2113: 2109: 2106: 2105: 2102: 2099: 2096: 2093: 2090: 2087: 2084: 2081: 2078: 2075: 2072: 2069: 2066: 2063: 2060: 2057: 2054: 2051: 2048: 2045: 2042: 2039: 2036: 2033: 2030: 2027: 2024: 2021: 2018: 2015: 2012: 2009: 2006: 2003: 2000: 1997: 1994: 1991: 1988: 1985: 1982: 1979: 1976: 1973: 1970: 1967: 1964: 1961: 1958: 1955: 1952: 1949: 1946: 1943: 1940: 1937: 1934: 1931: 1928: 1925: 1922: 1919: 1916: 1913: 1910: 1907: 1904: 1901: 1898: 1895: 1892: 1889: 1886: 1883: 1880: 1877: 1867: 1863: 1857: 1853: 1849: 1845: 1841: 1837: 1833: 1810:object-oriented 1805: 1801: 1794: 1789: 1780: 1775: 1767: 1763: 1755: 1751: 1747: 1739: 1737: 1728: 1727: 1724: 1721: 1718: 1715: 1712: 1709: 1706: 1703: 1700: 1697: 1694: 1691: 1688: 1686:// a mere int. 1685: 1682: 1679: 1676: 1673: 1670: 1667: 1664: 1661: 1658: 1655: 1652: 1649: 1646: 1643: 1640: 1637: 1634: 1631: 1628: 1625: 1622: 1619: 1616: 1613: 1610: 1607: 1604: 1601: 1598: 1595: 1592: 1589: 1586: 1583: 1580: 1577: 1574: 1571: 1568: 1565: 1562: 1559: 1556: 1553: 1550: 1547: 1544: 1541: 1538: 1535: 1532: 1523: 1522: 1519: 1516: 1513: 1510: 1507: 1504: 1501: 1498: 1495: 1492: 1489: 1486: 1483: 1480: 1477: 1474: 1471: 1468: 1465: 1462: 1459: 1456: 1453: 1450: 1447: 1444: 1441: 1438: 1435: 1432: 1429: 1426: 1423: 1420: 1417: 1414: 1411: 1408: 1405: 1402: 1399: 1396: 1389: 1388: 1385: 1382: 1379: 1376: 1373: 1370: 1367: 1364: 1361: 1358: 1355: 1352: 1349: 1346: 1343: 1340: 1337: 1334: 1331: 1328: 1325: 1322: 1319: 1316: 1313: 1310: 1307: 1304: 1301: 1298: 1288: 1284: 1283: 1280: 1277: 1275:constPtrToConst 1274: 1271: 1268: 1265: 1262: 1259: 1256: 1253: 1250: 1247: 1244: 1237: 1222: 1212: 1211: 1208: 1195: 1194: 1183: 1179: 1178: 1175: 1172: 1169: 1156: 1155: 1152: 1149: 1146: 1133: 1132: 1129: 1126: 1113: 1112: 1109: 1106: 1103: 1090: 1087: 1086: 1083: 1072: 1068: 1067: 1064: 1061: 1058: 1055: 1052: 1049: 1046: 1043: 1040: 1037: 1034: 1031: 997: 993: 985: 980: 979: 976: 973: 970: 968:constPtrToConst 967: 964: 961: 958: 955: 952: 949: 946: 943: 940: 937: 934: 931: 928: 925: 922: 919: 916: 913: 910: 907: 904: 897: 893: 889: 885: 881: 873: 872:, and read the 869: 865: 857: 853: 849: 845: 841: 837: 829: 826: 821: 820: 817: 814: 811: 808: 805: 803:constPtrToConst 802: 799: 796: 793: 790: 788:constPtrToConst 787: 784: 781: 778: 775: 772: 769: 766: 763: 760: 757: 754: 751: 748: 745: 742: 739: 736: 733: 730: 727: 724: 721: 718: 715: 712: 709: 706: 703: 700: 697: 694: 691: 688: 685: 682: 679: 677:constPtrToConst 676: 673: 670: 667: 664: 661: 658: 655: 652: 649: 646: 643: 640: 637: 634: 631: 628: 625: 622: 619: 616: 613: 606: 602: 597: 593: 583: 579: 575: 571: 567: 563: 559: 556: 547: 543: 539: 535: 531: 527: 524: 506: 502: 499: 476: 468: 464: 458: 453: 450: 441: 437: 431: 427: 422: 419: 406: 403:string literals 399: 383: 380:computer memory 376: 364:type conversion 355: 319: 311: 308: 307: 304: 301: 298: 295: 292: 289: 286: 283: 280: 277: 274: 271: 268: 265: 262: 259: 252: 248: 244: 240: 236: 224:is part of the 221: 217: 213: 208: 205: 202: 199: 196: 193: 184: 180: 176: 171: 168: 165: 162: 159: 156: 146:is part of the 143: 118: 82:memory location 57: 28: 23: 22: 15: 12: 11: 5: 4837: 4835: 4827: 4826: 4821: 4816: 4806: 4805: 4802: 4801: 4796: 4787: 4771: 4765: 4764:by Herb Sutter 4759: 4748: 4747:External links 4745: 4742: 4741: 4717: 4692: 4682:. Bugs.sun.com 4667: 4652: 4641: 4630: 4621: 4590: 4569: 4557: 4536: 4526:. 2022-06-13. 4508: 4490: 4476: 4455: 4432: 4418: 4381: 4348: 4315: 4282: 4254: 4240: 4213: 4163: 4138: 4137: 4135: 4132: 4129: 4128: 4115: 4094: 4085: 4068: 4054: 4053: 4051: 4048: 4047: 4046: 4041: 4036: 4029: 4026: 4001:keyword, with 3919: 3916: 3904:type qualifier 3853: 3852: 3837:C with Classes 3825: 3822: 3732: 3591: 3583:respectively. 3563:are "deep" or 3536: 3533: 3471: 3419: 3354: 3275: 3188: 3144: 3137:in the string 3116:type signature 3102: 3096: 3069: 3068: 3048: 3046: 3035: 3032: 2790: 2639: 2580:by means of a 2419: 2401: 2398: 2373:MyArray::Get() 2150: 2130:C const *const 2116:has the type " 1876: 1793: 1790: 1788: 1785: 1736: 1733: 1531: 1395: 1297: 1243: 1217: 1216: 1213: 1207: 1204: 1200: 1199: 1196: 1193: 1190: 1189:Continue right 1186: 1185: 1180: 1168: 1165: 1161: 1160: 1157: 1145: 1142: 1141:Continue right 1138: 1137: 1134: 1125: 1122: 1118: 1117: 1114: 1102: 1099: 1095: 1094: 1088: 1082: 1079: 1075: 1074: 1069: 1030: 1027: 1018: 1017: 1014: 1011: 1008: 984: 983:C++ convention 981: 903: 825: 822: 612: 555: 552: 523: 520: 498: 495: 449: 446: 418: 415: 375: 372: 366:) and C being 340:type signature 258: 249:int * const x; 245:int const * x; 117: 114: 72:, references, 42:type qualifier 26: 24: 14: 13: 10: 9: 6: 4: 3: 2: 4836: 4825: 4822: 4820: 4817: 4815: 4812: 4811: 4809: 4800: 4797: 4795: 4794:Walter Bright 4791: 4788: 4786: 4782: 4781: 4776: 4772: 4769: 4766: 4763: 4760: 4758: 4754: 4751: 4750: 4746: 4731: 4727: 4721: 4718: 4712: 4708: 4705: 4701: 4696: 4693: 4681: 4679: 4671: 4668: 4663: 4656: 4653: 4650: 4645: 4642: 4639: 4634: 4631: 4625: 4622: 4618: 4614: 4610: 4609:archive.today 4606: 4603: 4599: 4594: 4591: 4587: 4583: 4578: 4576: 4574: 4570: 4566: 4561: 4558: 4546: 4540: 4537: 4529: 4525: 4518: 4512: 4509: 4505: 4502: 4497: 4495: 4491: 4486: 4480: 4477: 4465: 4459: 4456: 4453: 4449: 4445: 4441: 4436: 4433: 4428: 4422: 4419: 4415: 4402: 4398: 4394: 4393: 4385: 4382: 4370: 4366: 4362: 4358: 4352: 4349: 4337: 4333: 4329: 4325: 4319: 4316: 4300: 4293: 4286: 4283: 4271: 4267: 4266: 4258: 4255: 4250: 4244: 4241: 4238: 4237:0-321-11358-6 4234: 4230: 4226: 4222: 4217: 4214: 4210: 4205: 4197: 4181: 4177: 4167: 4164: 4153: 4149: 4143: 4140: 4133: 4125: 4124:reserved word 4119: 4116: 4098: 4095: 4089: 4086: 4072: 4069: 4059: 4056: 4049: 4045: 4042: 4040: 4037: 4035: 4032: 4031: 4027: 4025: 4022: 4014: 4010: 4004: 3996: 3991: 3989: 3981: 3977: 3976:reserved word 3968: 3966: 3953: 3938: 3934: 3927: 3917: 3915: 3905: 3901: 3892: 3890: 3885: 3872: 3864: 3850: 3849: 3848: 3842: 3838: 3834: 3823: 3730: 3729: 3589: 3588: 3584: 3566: 3542: 3534: 3532: 3522: 3517: 3515: 3469: 3417: 3352: 3273: 3267: 3263: 3258: 3240: 3186: 3142: 3123: 3121: 3117: 3097: 3095: 3065: 3062:November 2014 3056: 3052: 3049:This section 3047: 3044: 3040: 3039: 3033: 3031: 3021: 3016: 3010: 2997: 2993: 2988: 2973: 2788: 2637: 2605: 2594:new int const 2583: 2417: 2405: 2399: 2397: 2395: 2148: 2137: 2124:" pointer to 2112:" pointer to 1874: 1871: 1860: 1852:objects. The 1831: 1827: 1823: 1819: 1815: 1811: 1799: 1791: 1786: 1784: 1773: 1761: 1745: 1734: 1732: 1680:// CONFUSING: 1605:// CONFUSING: 1529: 1526: 1445:// CONFUSING 1393: 1295: 1293: 1241: 1234: 1232: 1228: 1214: 1205: 1202: 1201: 1197: 1191: 1188: 1187: 1181: 1166: 1163: 1162: 1158: 1143: 1140: 1139: 1135: 1123: 1120: 1119: 1115: 1100: 1097: 1096: 1089: 1080: 1077: 1076: 1024: 1021: 1015: 1012: 1009: 1006: 1005: 1004: 1001: 990: 989:rule of thumb 982: 901: 880:to the left. 879: 863: 860:modifies the 835: 834:dereferencing 823: 610: 605:pointer to a 591: 590: 553: 551: 521: 519: 517: 513: 496: 494: 492: 488: 484: 479: 474: 469:object_type * 462: 447: 445: 434: 416: 414: 412: 404: 397: 393: 389: 381: 373: 371: 369: 368:call-by-value 365: 361: 360:type coercion 353: 349: 345: 341: 337: 333: 329: 325: 318:integer, but 317: 256: 233: 231: 227: 190: 153: 149: 140: 138: 134: 130: 126: 123: 115: 113: 111: 107: 103: 99: 95: 91: 87: 83: 79: 78:type-checking 75: 71: 67: 63: 55: 51: 48:applied to a 47: 43: 39: 35: 30: 19: 4778: 4733:. Retrieved 4729: 4720: 4695: 4684:. Retrieved 4677: 4670: 4655: 4644: 4633: 4624: 4616: 4612: 4593: 4588:, 2002, p. 5 4560: 4549:. Retrieved 4539: 4524:open-std.org 4523: 4511: 4500: 4479: 4468:. Retrieved 4458: 4443: 4440:Scott Meyers 4435: 4421: 4405:. Retrieved 4391: 4384: 4373:. Retrieved 4360: 4351: 4340:. Retrieved 4327: 4318: 4306:. Retrieved 4285: 4274:. Retrieved 4264: 4257: 4243: 4228: 4216: 4203: 4195: 4190:The type of 4189: 4183:. Retrieved 4179: 4166: 4155:. Retrieved 4151: 4142: 4118: 4097: 4088: 4083:is standard. 4071: 4058: 4021:block-scoped 4011: 3992: 3979: 3975: 3969: 3964: 3954: 3935: 3928: 3921: 3899: 3893: 3865: 3854: 3827: 3727: 3726: 3586: 3585: 3538: 3518: 3510: 3467: 3411: 3350: 3259: 3238: 3236: 3180: 3124: 3104: 3072: 3059: 3055:adding to it 3050: 2989: 2974: 2943: 2774: 2606: 2575: 2406: 2403: 2366: 2138: 2107: 1872: 1795: 1738: 1729: 1689:/* write: */ 1527: 1524: 1499:/* write: */ 1448:/* write: */ 1409:/* write: */ 1390: 1291: 1285: 1235: 1230: 1226: 1220: 1019: 1002: 986: 877: 861: 827: 824:C convention 587: 557: 525: 500: 451: 420: 413:unwritable. 410: 400:char const * 395: 391: 388:compile-time 377: 374:Consequences 344:return value 331: 323: 315: 309: 234: 229: 225: 151: 147: 141: 119: 116:Introduction 86:compile time 65: 37: 31: 29: 4785:Bruce Eckel 4757:Herb Sutter 4221:Herb Sutter 3887:keyword in 3710:mutableNums 3229:' ' 3214:'/' 3030:" version. 2598:LibraryFunc 2556:nonConstPtr 2550:LibraryFunc 2520:nonConstPtr 2493:LibraryFunc 2430:LibraryFunc 2136:" pointer. 1223:int const * 998:int * const 994:int const * 898:int const * 886:*ptrToConst 578:pointer to 386:-ness is a 183:type – the 125:declaration 4819:Data types 4808:Categories 4735:2017-10-31 4686:2014-11-04 4551:2013-08-18 4470:2017-11-23 4407:2022-12-23 4375:2022-12-23 4342:2022-12-23 4308:2022-12-23 4276:2022-12-21 4185:2020-03-30 4157:2022-06-22 4134:References 4013:JavaScript 3965:identifier 3575:object is 3565:transitive 3020:overloaded 2948:passed to 2743:bufferSize 2647:bufferSize 2582:const cast 2526:const_cast 2409:const_cast 2332:constArray 2287:constArray 2143:and a non- 2128:has type " 1774:– while a 1695:&& 1647:&& 1557:refToConst 1254:ptrToConst 1229:and not a 1225:becomes a 1078:Identifier 929:ptrToConst 894:ptrToConst 737:ptrToConst 722:ptrToConst 644:ptrToConst 574:value, or 448:Other uses 362:(implicit 352:containers 314:must be a 220:type: the 102:JavaScript 4773:Section " 4313:(8 pages) 3929:C# has a 3908:immutable 3779:immutable 3764:immutable 3692:constNums 3671:immutable 3656:immutable 3635:immutable 3581:immutable 3573:immutable 3561:immutable 3545:immutable 3082:in Java, 2692:textBox_t 2061:nonConstC 2022:nonConstC 1989:nonConstC 1822:Microsoft 890:int const 582:value. A 181:int const 54:constants 50:data type 4707:Archived 4617:volatile 4605:Archived 4528:Archived 4442:(2005). 4401:Archived 4369:Archived 4367:. 2010. 4336:Archived 4334:. 2010. 4299:Archived 4270:Archived 4268:. 2006. 4227:(2005). 4176:pointer" 4107:volatile 4039:restrict 4028:See also 4007:constant 3999:constant 3884:restrict 3875:volatile 3845:readonly 3356:template 3266:template 3088:readonly 3034:Problems 2783:has all 2118:C *const 1840:and non- 1832:. While 1772:contract 1626:constRef 1215:doubles. 1093:is a ... 947:constPtr 870:int* ptr 838:int *ptr 770:constPtr 755:constPtr 659:constPtr 512:compiler 438:volatile 433:volatile 324:constant 316:variable 222:constant 200:constant 137:variable 129:constant 70:pointers 62:C family 32:In some 4726:"const" 4081:char* s 4077:char *s 3980:keyword 3879:noalias 3861:* const 3824:History 3101:problem 2970:mutable 2278:MyArray 2266:MyArray 2155:MyArray 1826:C++/CLI 1792:Methods 1641:// C++: 1071:Meaning 856:. Thus 589:pointee 483:caching 478:mutable 461:pointer 218:INTEGER 203:INTEGER 60:in the 46:keyword 4680:]" 4450:  4235:  4109:, not 4103:shared 4015:has a 3995:Ada 83 3939:has a 3857:inline 3525:strchr 3519:Since 3479:strchr 3433:strchr 3374:strchr 3319:strchr 3283:strchr 3202:strchr 3183:strchr 3152:strchr 3131:strchr 3127:strchr 3099:strchr 3015:strchr 3009:strstr 2792:struct 2755:struct 2749:sizeof 2725:size_t 2704:rect_t 2665:size_t 2641:size_t 2242:return 2200:return 2170:public 2082:constC 2046:constC 2004:constC 1920:return 1896:public 1820:or in 1744:static 1292:before 1209:double 1150:double 1062:double 1032:double 844:is an 497:Syntax 489:, and 392:should 281:// ... 226:object 152:object 131:: its 122:object 108:, and 76:, and 4700:1815A 4613:const 4531:(PDF) 4520:(PDF) 4302:(PDF) 4295:(PDF) 4172:"The 4111:const 4064:const 4050:Notes 4017:const 3984:const 3972:const 3961:final 3957:const 3950:const 3946:const 3941:const 3931:const 3924:const 3912:inout 3902:(not 3896:const 3867:const 3829:const 3734:class 3686:const 3614:const 3577:const 3569:const 3557:const 3553:const 3549:const 3529:const 3488:const 3439:inout 3421:inout 3414:inout 3328:const 3313:const 3270:const 3255:const 3251:const 3247:const 3243:const 3112:const 3107:const 3092:const 3084:const 3080:final 3076:const 3028:const 3024:const 3004:const 3000:const 2985:const 2981:const 2977:const 2966:const 2958:const 2954:s.ptr 2950:Foo() 2900:& 2840:& 2837:const 2785:const 2781:const 2777:const 2734:& 2668:const 2644:const 2634:const 2630:const 2626:const 2622:const 2618:const 2614:const 2610:const 2590:const 2578:const 2568:// OK 2535:*> 2469:const 2413:const 2382:const 2369:const 2302:array 2284:& 2281:const 2272:array 2269:& 2236:const 2218:& 2215:const 2179:& 2152:class 2145:const 2141:const 2126:Get() 2114:Set() 2034:// Ok 2001:& 1998:const 1986:& 1911:const 1878:class 1864:const 1854:const 1850:const 1846:const 1842:const 1838:const 1834:const 1806:const 1802:const 1781:const 1776:const 1768:const 1756:const 1748:const 1740:const 1716:value 1668:value 1623:const 1620:& 1578:& 1575:const 1569:// OK 1554:& 1551:const 1380:const 1374:const 1359:const 1338:const 1317:const 1289:const 1272:const 1263:const 1245:const 1238:const 1176:const 1041:const 965:const 959:const 944:const 923:const 896:is a 888:is a 874:const 858:const 674:const 668:const 656:const 638:const 607:const 603:const 598:const 594:const 584:const 580:const 576:const 572:const 568:const 564:const 560:const 540:const 528:const 507:const 503:const 454:const 442:const 428:const 423:const 411:often 407:const 405:), C 384:const 356:const 322:is a 287:const 272:& 253:const 237:const 185:const 160:const 144:const 133:value 106:Julia 58:const 40:is a 38:const 4615:and 4448:ISBN 4233:ISBN 4223:and 4192:this 4174:this 3910:and 3797:next 3746:next 3716:nums 3698:nums 3662:nums 3559:and 3555:, D 3485:char 3473:char 3445:char 3427:char 3365:> 3359:< 3325:char 3310:char 3289:char 3277:char 3181:The 3158:char 3146:char 3105:The 3086:and 3012:and 2825:void 2659:1024 2562:size 2529:< 2505:size 2484:size 2457:void 2451:size 2427:void 2378:this 2367:The 2257:void 2245:data 2203:data 2164:data 2134:this 2122:this 2110:this 1974:void 1932:void 1868:this 1859:this 1816:and 1814:Java 1766:. A 1698:rref 1650:rref 1593:ref3 1581:ref2 878:type 862:name 842:*ptr 809:NULL 776:NULL 743:NULL 710:NULL 614:void 459:this 430:and 260:void 230:type 148:type 110:Rust 66:type 4792:by 4783:by 4755:by 4730:MDN 4678:sic 4600:, " 3937:Nim 3889:C99 3871:C89 3841:C++ 3835:in 3803:num 3791:foo 3785:Foo 3776:new 3770:foo 3767:Foo 3755:num 3752:int 3743:Foo 3737:Foo 3707:int 3689:int 3677:int 3668:new 3659:int 3647:foo 3641:baz 3638:int 3626:foo 3620:bar 3617:int 3605:int 3602:new 3596:foo 3593:int 3579:or 3571:or 3521:C23 3500:int 3457:int 3404:... 3392:int 3340:int 3301:int 3241:be 3239:can 3170:int 3057:. 2996:C23 2921:ptr 2894:ptr 2873:val 2852:int 2828:Foo 2816:ptr 2810:int 2804:val 2801:int 2767:... 2683:int 2680:... 2602:ptr 2586:ptr 2541:ptr 2532:int 2514:int 2499:ptr 2481:int 2475:ptr 2466:int 2448:int 2442:ptr 2436:int 2396:.) 2390:int 2386:int 2338:Get 2308:Get 2260:Foo 2227:int 2221:Get 2212:int 2188:int 2182:Get 2176:int 2161:int 2088:Set 2067:Set 2055:(); 2052:Get 2037:int 2031:(); 2028:Get 2013:int 1977:Foo 1941:int 1935:Set 1905:Get 1902:int 1887:int 1828:or 1824:'s 1787:C++ 1704:int 1692:int 1656:int 1644:int 1632:var 1617:int 1599:var 1587:var 1572:int 1563:var 1548:int 1536:var 1533:int 1502:int 1475:int 1451:int 1427:int 1412:int 1397:int 1383:ptr 1371:int 1362:ptr 1353:int 1344:ptr 1332:int 1323:ptr 1314:int 1305:ptr 1299:int 1266:int 1248:int 1107:int 1091:fun 1084:fun 1059:))( 1056:int 1050:fun 956:int 938:int 920:int 911:ptr 905:int 854:int 850:ptr 846:int 704:ptr 689:ptr 665:int 650:int 635:int 629:ptr 623:int 617:Foo 546:or 444:). 409:is 396:can 284:int 269:int 216:of 189:Ada 179:of 157:int 94:C++ 44:(a 4810:: 4728:. 4702:, 4584:, 4572:^ 4522:. 4493:^ 4363:. 4359:. 4330:. 4326:. 4209:". 4204:cv 4188:. 4178:. 4150:. 3952:. 3788:); 3680:); 3516:. 3506:); 3463:); 3448:)* 3430:)* 3346:); 3307:); 3217:)) 3190:if 3176:); 3122:. 2861:42 2822:}; 2761:); 2604:. 2565:); 2544:); 2508:); 2454:); 2353:42 2323:42 2254:}; 2097:); 2094:10 2076:); 2073:10 1971:}; 1908:() 1818:C# 1722:10 1713:), 1674:10 1665:), 1542:22 1377:** 1356:** 1320:** 1302:** 1233:. 1173:** 1153:)) 1110:)) 1065:)) 1038:** 485:, 305:); 278:); 232:. 209:1_ 206::= 191:, 112:. 104:, 100:, 96:, 92:, 56:, 36:, 4738:. 4713:: 4689:. 4664:. 4554:. 4487:. 4473:. 4429:. 4410:. 4378:. 4345:. 4311:. 4279:. 4207:X 4200:X 4160:. 4113:. 3812:; 3809:5 3806:= 3800:. 3794:. 3782:( 3773:= 3761:} 3758:; 3749:; 3740:{ 3719:; 3713:= 3701:; 3695:= 3674:( 3665:= 3650:; 3644:= 3629:; 3623:= 3608:; 3599:= 3535:D 3503:c 3497:, 3494:s 3491:* 3482:( 3476:* 3460:c 3454:, 3451:s 3442:( 3436:( 3424:( 3407:} 3401:{ 3398:) 3395:c 3389:, 3386:s 3383:* 3380:T 3377:( 3371:* 3368:T 3362:T 3343:c 3337:, 3334:s 3331:* 3322:( 3316:* 3304:c 3298:, 3295:s 3292:* 3286:( 3280:* 3232:; 3226:= 3223:p 3220:* 3211:, 3208:q 3205:( 3199:= 3196:p 3193:( 3173:c 3167:, 3164:s 3161:* 3155:( 3149:* 3139:s 3135:c 3064:) 3060:( 2962:s 2946:s 2939:} 2930:; 2927:i 2924:= 2918:. 2915:s 2912:* 2906:; 2903:i 2897:= 2891:. 2888:s 2882:; 2879:i 2876:= 2870:. 2867:s 2864:; 2858:= 2855:i 2849:{ 2846:) 2843:s 2834:S 2831:( 2819:; 2813:* 2807:; 2798:{ 2795:S 2770:} 2752:( 2746:- 2740:= 2731:) 2728:* 2722:( 2719:* 2716:{ 2713:) 2707:* 2701:, 2695:* 2689:( 2674:; 2662:; 2656:* 2653:8 2650:= 2571:} 2559:, 2553:( 2538:( 2523:= 2517:* 2502:, 2496:( 2490:{ 2487:) 2478:, 2472:* 2463:( 2445:, 2439:* 2433:( 2376:" 2362:} 2356:; 2350:= 2347:) 2344:5 2341:( 2335:. 2326:; 2320:= 2317:) 2314:5 2311:( 2305:. 2293:{ 2290:) 2275:, 2263:( 2251:} 2248:; 2239:{ 2233:) 2230:i 2224:( 2209:} 2206:; 2197:{ 2194:) 2191:i 2185:( 2173:: 2167:; 2158:{ 2103:} 2091:( 2085:. 2070:( 2064:. 2049:. 2043:= 2040:x 2025:. 2019:= 2016:y 2010:{ 2007:) 1995:C 1992:, 1983:C 1980:( 1968:} 1965:; 1962:j 1959:= 1956:i 1953:{ 1947:) 1944:j 1938:( 1929:} 1926:; 1923:i 1917:{ 1899:: 1893:; 1890:i 1884:{ 1881:C 1725:; 1719:= 1710:5 1707:( 1701:= 1677:; 1671:= 1662:5 1659:( 1653:= 1635:; 1629:= 1602:; 1596:= 1590:, 1584:= 1566:; 1560:= 1545:; 1539:= 1520:; 1517:b 1514:* 1511:, 1508:a 1505:* 1493:; 1490:b 1487:* 1484:, 1481:a 1478:* 1466:; 1463:b 1460:, 1457:a 1454:* 1442:; 1439:b 1436:, 1433:a 1430:* 1421:; 1418:a 1415:* 1406:; 1403:a 1400:* 1341:* 1335:* 1308:; 1278:; 1269:* 1257:; 1251:* 1170:( 1147:( 1130:* 1127:( 1104:( 1053:( 1047:* 1044:( 1035:( 971:; 962:* 950:; 941:* 932:; 926:* 914:; 908:* 866:* 830:* 818:} 812:; 806:= 797:; 794:0 791:= 785:* 779:; 773:= 764:; 761:0 758:= 752:* 746:; 740:= 731:; 728:0 725:= 719:* 713:; 707:= 698:; 695:0 692:= 686:* 683:{ 680:) 671:* 662:, 653:* 647:, 641:* 632:, 626:* 620:( 320:i 312:f 302:i 299:( 296:f 293:; 290:i 275:x 266:( 263:f 214:X 197:: 194:X 177:x 172:; 169:1 166:= 163:x 98:D 90:C 20:)

Index

Const correctness
programming languages
type qualifier
keyword
data type
constants
C family
pointers
composite data types
type-checking
memory location
compile time
C
C++
D
JavaScript
Julia
Rust
object
declaration
constant
value
variable
Ada
program correctness
programming by contract
type signature
return value
composite data types
containers

Text is available under the Creative Commons Attribution-ShareAlike License. Additional terms may apply.