} However, any attempt to modify an object that is itself declared const by means of a const cast results in undefined behavior according to the ISO C++ Standard. In the example above, if ptr references a global, local, or member variable declared as const, or an object allocated on the heap via new int const, the code is only correct if LibraryFunc really does not modify the value pointed to by ptr. 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 elements like variable names, whether the initializer elements are declared const or not, or whether the static duration variable is being declared const or not. There is a non-portable way to initialize a const variable that has static storage duration. By carefully constructing a typecast on the left hand side of a later assignment, a const variable can be written to, effectively stripping away the const attribute and 'initializing' it with non-constant elements like other const variables and such. Writing into a const variable this way may work as intended, but it causes undefined behavior and seriously contradicts const-correctness: size_t const bufferSize = 8*1024; size_t const userTextBufferSize; //initial value depends on const bufferSize, can't be initialized here ... int setupUserTextBox(textBox_t *defaultTextBoxType, rect_t *defaultTextBoxLocation) { *(size_t*)&userTextBufferSize = bufferSize - sizeof(struct textBoxControls); // warning: might work, but not guaranteed by C ... } Another loophole applies both to C and C++. Specifically, the languages dictate that member pointers and references are "shallow" with respect to the const-ness of their owners — that is, a containing object that is const has all const members except that member pointees (and referees) are still mutable. To illustrate, consider this C++ code: struct S { int val; int *ptr; }; void Foo(S const & s) { int i = 42; s.val = i; // Error: s is const, so val is a const int s.ptr = &i; // Error: s is const, so ptr is a const pointer to int *s.ptr = i; // OK: the data pointed to by ptr is always mutable, // even though this is sometimes not desirable } Although the object s passed to Foo() is constant, which makes all