Hi,
Thanks to both of the answer providers.
I forgot that I am writing to a platform independent group when I was
talking mostly about the implementation on Windows.
So now I understood that it is a requirement by the language standard itself
to have a zero initliazed static and globals which has nothing to do with
the memory storage.
Thanks
Abhishek
"Thomas Matthews" <Thomas_MatthewsSpamBotsSuck@sbcglobal.net> wrote in
message news:41E54F4D.7080604@sbcglobal.net...[color=blue]
> Abhishek Pandey wrote:[color=green]
> > Hi All,
> > A basic question.
> > In C (and C++ also) global and static variables which are un-initalized[/color][/color]
are[color=blue][color=green]
> > guaranteed to be zero. This is because (as per my knowledge) they are[/color][/color]
all[color=blue][color=green]
> > stored in the uninitialized section of Data Segment (also called as BSS[/color][/color]
if I[color=blue][color=green]
> > am right) and that section is all set to NULL when the program starts.[/color]
> Wrong. If any guarantees are made, this is because of either the
> language specification or the compiler manual. It has nothing to do
> with where the variables are stored. The variables are allowed to be
> stored anywhere, as long as the access and behavior matches the
> statements in the standard.
>
> There is no requirement by the C++ language specification for an
> implementation to have a data segment, BSS, or code segment.
>
>
>[color=green]
> > My question is whether it is true for systems other than windows also ?[/color]
> Some platforms have data segments, some don't. Depends on the
> implementation (compiler and linker). Some platforms may have more
> segments.
>[color=green]
> > And
> > Where are static and global variables stored in other systems ?[/color]
> There are many systems out there and I'm sure that you don't
> want to know about all of them (especially the plethora of
> custom embedded systems).
>
> All you can be guaranteed of is:
> 1. Non-const variables are stored in places that have read and
> write access.
> 2. Const variables (i.e. data) are may be stored in locations
> that have read-only access or read and write access.
>
> So, why do you need to know where the variables are stored?
> Just initialize variables before you use them and concentrate
> on making your program work correctly and robustly. After
> that, then worry about size and speed.
>[color=green]
> >
> > Thanks
> > Abhishek
> >
> >[/color]
>
>
>
> --
> Thomas Matthews
>
> C++ newsgroup welcome message:
>
http://www.slack.net/~shiva/welcome.txt
> C++ Faq:
http://www.parashift.com/c++-faq-lite
> C Faq:
http://www.eskimo.com/~scs/c-faq/top.html
> alt.comp.lang.learn.c-c++ faq:
>
http://www.comeaucomputing.com/learn/faq/
> Other sites:
>
http://www.josuttis.com -- C++ STL Library book
>
http://www.sgi.com/tech/stl -- Standard Template Library
>[/color]