delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/08/26/12:55:17

Reply-To: <arfa AT clara DOT net>
From: "Arthur" <arfa AT clara DOT net>
To: "DJGPP Mailing List" <djgpp AT delorie DOT com>,
"Klaus Petzold" <califax AT wupperonline DOT de>
Subject: RE: Problem with "new"
Date: Wed, 26 Aug 1998 17:53:20 +0100
Message-ID: <000001bdd112$07f8bc00$214e08c3@arthur>
MIME-Version: 1.0
In-reply-to: <35e404cf.33475@news.space.net>
Importance: Normal

> Hi,
> 
> I use gcc version 2.7.2.1 and I try to reserve some memory with "new".
> My problem is, if there is not enough memory the program returns to
> the OS (code 255), what I don't want.
> How can I avoid this?
> 
> tia...
>   ...Klaus...
>   
> 

new returns NULL if memory allocation fails. You should always test for this.

eg:

int *a;
a = new int;
if(!a){ do_something() }

I think this should work.

James Arthur
jaa AT arfa DOT clara DOT net
ICQ#15054819 

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019