Arindam Biswas <[EMAIL PROTECTED]> wrote:
>
> Hi Friends,
> 
> One simple doubt:
> 
> const int a = 10; // global
> my_function()
> {
> const int b = 20; // local
> }
> 
> Will both 'a' and 'b' be stored in data segment?

Why do you care?

What's more important is whether const means 'constant' or
'don't write'. It means the latter.

So in the above fragments, you tell the compiler that
the code will not modify the values of a or b after
their initialisation.

The compiler is now required to issue a diagnostic
if you attempt to directly write to them, or if you
attempt to pass their address to a function taking
a non const qualified object pointer (assuming you
don't attempt to fool the compiler by casting).

In other words, const is a tool for protecting against
accidental writes. It is not generally a tool for
putting objects into certain locations of memory
or executables.

-- 
Peter

Reply via email to