Flash Gordon <> writes:
> Szabolcs Borsanyi wrote, On 26/05/08 10:18:
[...]
>> The qualifiers (e.g. const, volatile) do not affect the storage, but they
>> do have an impact on the access to those variables.
>
> Incorrect. On a lot of systems const will cause "variables" to be
> stored in some form of read-only memory, either actual ROM or a page
> that the OS will mark as read only when it loads the program.
[...]
That can happen only if the initial value can be determined at
compilation time.
For example, this is a valid declaration (if it appears within a
function, and assuming the required headers have been #included):
const time_t now = time(NULL);
For that matter, if an object's initial value can be determined at
compilation time and the compiler can determine that it's never
modified, the compiler is free to store it in ROM even if it's not
declared const (though in that case it *should* have been declared
const).
--
Keith Thompson (The_Other_Keith)
kst- <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"