Re: storage locations for different data types
From: Allan W (allan_w_at_my-dejanews.com)
Date: 01/13/05
- Next message: Arkadiy: "Re: convert a c++ program into a template metaprogram?"
- Previous message: Victor Bazarov: "Re: VS6 project fails to build after .NET 03 install"
- In reply to: Maciej Sobczak: "Re: storage locations for different data types"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 13 Jan 2005 17:20:00 -0500
> smith4894@excite.com wrote:
> > 1)Where are global non-const objects created?
Maciej Sobczak wrote:
> In some other place, which is a "static storage".
> Typically, the memory for all objects with static storage duration
> (collectively) is assigned to the process when the program is loaded
> into memory. Alternatively, it may be even part of the program (of
the
> file on disk) itself, but any other strategy is allowed, as long as
the
> lifetimes of the objects obey the rules. It all depends on
implementation.
>
> > 2)Where are global const objects created?
>
> Same as global non-const. This is static storage.
> The const qualifier affects only what you can do with them, not where
> they are.
I realize that you're answering a beginner's question, so you don't
want to get too technical. But I think it's important to point out
that const statics CAN be treated differently from non-const statics.
The definitive example is that embedded systems, where const statics
can be put into read-only memory, along with the program code. But it
isn't just embedded systems. A system with protected memory could
put a const object (even a const auto object) into a section of
memory, and then write-lock that section of memory until it's time
to run the destructor.
That's the main reason for the limitations on const_cast: If you cast
a pointer-to-const into a pointer-to-non-const, and the object truely
was a const object, you get undefined behavior.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
- Next message: Arkadiy: "Re: convert a c++ program into a template metaprogram?"
- Previous message: Victor Bazarov: "Re: VS6 project fails to build after .NET 03 install"
- In reply to: Maciej Sobczak: "Re: storage locations for different data types"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|