This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Memory initialization (not)
- From: Mihai DonÈu <mihai dot dontu at gmail dot com>
- To: gcc-help at gcc dot gnu dot org
- Cc: Jim Dougherty <j_dougherty at ecrm dot com>
- Date: Tue, 30 Sep 2008 16:53:33 +0300
- Subject: Re: Memory initialization (not)
- References: <48E22C5B.3090503@ecrm.com>
On Tuesday 30 September 2008, Jim Dougherty wrote:
> I have a section of memory that I do not want to be initialized with
> zeros when my program starts.
> Is there a way to achieve this?
I think that zero initialization is a consequence of how the process images is
created. For example:
static char a[65536];
will make the .bss section of size ~65536 bytes which is allocated by the
dynamic linker by means of mmap() which always provides zeroed-out pages.
So to answer your question: global variables are likely to be always
initialized with zero (it's out of gcc-s hands). Stack variables, on the
other hand, are "initialized" with whatever is on the stack, which yeah, if
you don't explicitly initialize them, could be called uninitialized. :)
--
Mihai DonÈu (unices@bitdefender.com)