www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/02/16/14:46:10

From: "Scott Deming" <sdeming AT concentric DOT net>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: delete NULL?
Date: 16 Feb 1997 18:34:43 GMT
Organization: NCR Corporation
Lines: 31
Message-ID: <01bc1c37$c96eebc0$f676adce@midetrdemins.Detroitmi.ncr.com>
References: <19970216 DOT 124451 DOT 7287 DOT 0 DOT fwec AT juno DOT com>
NNTP-Posting-Host: cnc805246.concentric.net
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

> I just finished writing a C++ implementation of a circular linked list.
> 
> My question is this.  If I use delete on a pointer which is equal to
> NULL,
> for example...
> 
> char *ptr = NULL;
> 
> delete ptr;
> 

[snip]

It would be very advisable to something like:

if (ptr != NULL)
	delete ptr;

I imagine it's very bad to delete a NULL ptr, but as I don't know the C++
specification to those kind of details, it may be perfectly legal.  Still,
it's poor practice to operate on a NULL ptr in any way.

> 
> TIA
> 
> -Fwec
> 

Good luck.


- Raw text -


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