cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1997/02/16/15:00:54

From: gfoot AT mc31 DOT merton DOT ox DOT ac DOT uk (George Foot)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: delete NULL?
Date: 16 Feb 1997 18:34:50 GMT
Organization: Oxford University
Lines: 21
Message-ID: <5e7k0a$o51@news.ox.ac.uk>
References: <19970216 DOT 124451 DOT 7287 DOT 0 DOT fwec AT juno DOT com>
NNTP-Posting-Host: mc31.merton.ox.ac.uk
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Mark T Logan (fwec AT juno DOT com) wrote:

: My question is this.  If I use delete on a pointer which is equal to
: NULL,
: for example...

: char *ptr = NULL;

: delete ptr;

: Will anything bad happen?  I have written the linked list to be as simple

I'm not sure whether or not delete minds being passed NULL, but you could
replace the 'delete ptr' line with 'if (ptr) delete ptr;' - then it won't be
executed if ptr is NULL. Since this code isn't called often, the slightly 
inefficiency in adding this extra condition if delete already performs such 
a check will not be noticeable in your program.

-- 
George Foot <gfoot AT mc31 DOT merton DOT ox DOT ac DOT uk>
Merton College, Oxford.

- Raw text -


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