....a.cpp....
#include<iostream>
ClassA aObj;
char chArray[10];
ClassB bObj;
static int bInt;
func();
My question is in which order the memory is allocated to the global
objects on the heap space. Can we expect the memory of all the object
aObj,chArray, bObj and bInt to be in a sequence in memory. Or its a
compiler dependent? Does compiler optimization can affect the order in
which memory is allocated ?
TIA
-Vikram
They're not allocated on the heap, they're in the program's data
segment. They're initialized in the same order they're given in the
code.
Joe
--
"Surprise me"
- Yogi Berra when asked where he wanted to be buried.
AFAIK, they're initialized in the order the compiler chooses to
initialize them.
--
__Pascal Bourguignon__ http://www.informatimago.com/
Nobody can fix the economy. Nobody can be trusted with their finger
on the button. Nobody's perfect. VOTE FOR NOBODY.
> j...@invalid.address writes:
> > "Vikram" <vsac...@gmail.com> writes:
> > > My question is in which order the memory is allocated to the global
> > > objects on the heap space. Can we expect the memory of all the
> > > object aObj,chArray, bObj and bInt to be in a sequence in memory. Or
> > > its a compiler dependent? Does compiler optimization can affect the
> > > order in which memory is allocated ?
> >
> > They're not allocated on the heap, they're in the program's data
> > segment. They're initialized in the same order they're given in
> > the code.
>
> AFAIK, they're initialized in the order the compiler chooses to
> initialize them.
I think that's true for C, but the example was in C++, which defines
the order.
It defines the order in which their initializers are run, but I really
doubt that the language says anything about the order of their memory
addresses.
--
Barry Margolin, bar...@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
To Vikram and Ahalom -- why aren't your messages properly linked into
the thread that was started? Doesn't Google have a proper
reply/followup operation?
I know that Vikram was using Google Groups 2
(http://groups-beta.google.com), the most buggy website on the WWW
right now. I am not surprised that even the most things don't work.
Adnan
PS - I am using Google Groups 2 too.