Advertisements

(Mantorok Redgormor) writes:
> strictly speaking we can't say that const means "read only" but
> instead that it means "do not modify me please" since an object can be
> both modifiable and not modifiable or volatile and const, right?

Not sure what you mean by that. If you have something like

const int i = 5;

then every attempt to modify `i' is an error. OTOH, if you have

int i = 5;
const int *ip = &i;

you can modify `i' directly, but it's an error to modify it through `ip'
(e.g. by assigning to `*ip').
> and if an implementation chose to put things that are const in read
> only memory if that const thing was also volatile then in that case,
> it would not be in read only memory, correct?

Not necessarily. If you have

const volatile int i = 5;

the implementation could still put `i' in read only memory. Perhaps a
better example is

const volatile int *ip = some_system_specific_initialization ();

It would still be an error to modify `*ip' in any way, but the
implementation would have to assume that the object pointed to can be
changed by something beyond its control. Imagine, for example, that
`some_system_specific_initialization ()' returns the address of a
hardware timer, which is incremented regularly by the hardware, but
cannot be changed by the C program.

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!