:I imagine to implement memory areas that are updated to be "read-only"
:after an initial assignment.
I seem to recall hearing of such a property in C++, but not in
C -- at least not in C89. The 'const' attribute in C is handled at
the compiler level, not the OS level.
No more in C++ than C. There are two other things you (or anyone else)
might have confused with this:
In C++ as in C you have const-qualified objects, and members of a
struct (in C++ also class), which can be initialized in the defining
declaration (of an instance) but not assigned to thereafter. If a
struct or class instance is const this means you can't assign to it or
to any member of it -- const 'distributes'. In C++ you can declare a
member 'mutable' which means that it can be assigned even in an
instance that is const or is 'promoted' to const; this is intended to
be used for 'hidden' (at least protected) data which is used within
the class's methods but does not affect the OO-ish state, such as
memoization/cache, hidden resources, debugging, etc.
C++ allows definitions of class instances (const or not) to specify
initial values that imply running a (particular) constructor rather
than just storing a value or list of values. This includes
static-duration objects, which in C (and in C++ for C-like 'POD'
types) can be and normally are 'initialized' at compile/link time. To
allow this C++ breaks initialization of statics into two pieces --
'static initialization' which has the same capabilities as C (zeros,
fixed values, addresses of other static objects) and is normally done
in the executable file, and 'dynamic initialization' which can be and
usually is done by running the constructor at runtime, after process
startup but before the object is used. An implementation thus _might_
reasonably put const-qualified static objects in a memory area that is
writable while it does the dynamic initialization and is then made
unwritable. (But I don't know of any that actually do.)
Generally speaking, the C standard disavows all knowledge of the
OS facilities beyond the existance of the narrowly-defined
file I/O operators. C does not require that memory protection
exists on the system at all.
And optionally ability to execute commands (of some sort); and real
(wall) and CPU clocks. And (things that might map to) signals.
And in C99 with optional 60559, certain controls and inquiries on FPU
settings, which might involve OS or might just go to hardware.
- David.Thompson1 at worldnet.att.net