From: Sengan DOT Short AT durham DOT ac DOT uk Message-Id: <19792.9607091459@ws-ai5.dur.ac.uk> Subject: Re: What if I run out of store To: j DOT aldrich6 AT genie DOT com Date: Tue, 9 Jul 1996 15:59:50 +0100 (BST) Cc: djgpp AT delorie DOT com In-Reply-To: <199607090525.AA200249924@relay1.geis.com> from "j.aldrich6@genie.com" at Jul 9, 96 05:00:00 am Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit > > 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 ', 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