Mail Archives: djgpp/1996/07/09/11:06:53
>
> Reply to message 5864967 from A DOT APPLEYARD AT F on 07/08/96 8:49AM
>
>
> > Excuse me if this query is rather faqqish, but, since in version 2 I am not
> >allowed indefinite heap size:-
>
> I can't think of any DPMI compiler that doesn't allow you indefinite
> heap size - are you perhaps thinking of the stack? Heap size is
> limited only by the amount of free memory you have.
>
> > (1) In (a) version 1, (b) in version 2, (c) in C and C++ in general
> >including non-Gnu compilers, what happens if I call `new <typename>', or
> >malloc(), and there is not enough space available, what happens? I used to
> >think that it merely returns 0, but after finding this function in
> >c:\djgpp\libsrc\gcc\src\libgcc2.c_:-
> > void _default_new_handler(){write(2,MESSAGE,sizeof(MESSAGE)); _exit(-1);}
> > I no longer feel so certain.
Hmm... In ``The C++ programming language'' by Stroustrup it says p499
``Initialisation is done only if the value returned by the operator new() is
nonzero. If the value returned bythe operator new() is 0 (the null pointer)
the value of the expression is 0''.
So; as far as I understand it, it should return 0.
I think the above code is used if you are trying to build an object which has
not had a new operator defined for it. Clearly gcc will fail in that case.
I suppose you could do some fancy exception handling stuff to cope with such
errors, but recovering from a semi defined object would be non-trivial.
Otherwise gcc has little choice but to abort the program and say that it does
not know how to build an object of that type. exit(-1) would be what the return
value of the whole program (and not the new operator) would be.
Sengan
- Raw text -