[lug] new operator in C++

David Morris lists at morris-clan.net
Sat Apr 27 16:00:18 MDT 2002


Sheesh people, try *reading* the question.

New memory is never *guaranteed* to be initialized.  A few (and as far as I
know this is the exception, NOT the rule) will initialize dynamic (or even
static) memory allocation to zero, but it it NOT standard and if you count
on it this is always a bug in your code.

Note that just because it looks like a variable has been initialized, does
not mean it has been initialized....the default state of memory is zero,
and there are many cases where you will get the default state of memory
rather than whatever was there last....in fact, this is more normal now
that to get some old contents of memory, which is why programs can
sometimes get by *without* initializing variables.

Never rely on C/C++ to provide a valid initial value, or you will
eventually come up with one of the more annoying bugs in existance.

Hope this helps...

--David


-- 
"I might not agree with what you say,
    but I will defend to the death your right to say it!"
  --Voltaire


Quoting Stephen Queen <svq at peakpeak.com>:

> In using the new operator in C++ I cannot find whether it is
> guaranteed
> to initialize the new memory to zero or not. In playing with it, it
> looks like it does, but that might be coincidence. Does anyone know a
> source of information on the net regarding this? Another question
> regarding sources of information on C++. man has section 3 which is a
> good source of information for regular C. Does anyone know of anything
> like that for C++? It sure would come in handy now and then.
> 
> Thanks,
> Steve Queen
> 
> _______________________________________________
> Web Page:  http://lug.boulder.co.us
> Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug
> Join us on IRC: lug.boulder.co.us port=6667 channel=#colug
> 


-------------------------------------------------
This mail sent through IMP: http://horde.org/imp/



More information about the LUG mailing list