[lug] new operator in C++

Stephen Queen svq at peakpeak.com
Sat Apr 27 14:28:53 MDT 2002

"D. Stimits" wrote:

> Older compilers behaved similar to malloc, and returned NULL if failed.
> Newer ones (g++) will throw an exception. To override this and get older
> NULL behavior, you can create your own custom allocator, or else do the
> easy thing, use the nothrow argument. E.G.:
>   myClass* oTheClass = NULL;
>   oTheClass = new(nothrow) myClass;
>   assert(oTheClass);
> D. Stimits, stimits at idcomm.com
> PS: If in doubt, just use (nothrow) and see if the compiler
> complains...if it doesn't, then you have a compiler that supports
> exception throwing for failures of new.
> _______________________________________________

Let me rephrase my question. In the following example,

int* intptr=new int;

Is the newly created memory's value guaranteed to be zero. Will the out put
of the example be guaranteed to be zero.

More importantly, where is a good source of information on this? Do I need
to just start digging through the include header files to figure this stuff
out? I can do that, but it is sooo time consuming, and if some one has
already documented it, where can I find it?

More information about the LUG mailing list