delorie.com/archives/browse.cgi | search |
From: | "Edmund Horner" <ejrh AT paradise DOT net DOT nz> |
Newsgroups: | comp.os.msdos.djgpp |
References: | <8q1u4s$jh3$1 AT info DOT cyf-kr DOT edu DOT pl> |
Subject: | Re: deleting NULL ? |
Lines: | 38 |
X-Priority: | 3 |
X-MSMail-Priority: | Normal |
X-Newsreader: | Microsoft Outlook Express 5.50.4133.2400 |
X-MimeOLE: | Produced By Microsoft MimeOLE V5.50.4133.2400 |
Organization: | Paradise Net |
Message-ID: | <969182875.671530@shelley.paradise.net.nz> |
Cache-Post-Path: | shelley.paradise.net.nz!unknown AT 203-96-148-241 DOT tnt0 DOT paradise DOT net DOT nz |
X-Cache: | nntpcache 2.4.0b5 (see http://www.nntpcache.org/) |
Date: | Sun, 17 Sep 2000 21:30:18 +1200 |
NNTP-Posting-Host: | 203.96.152.26 |
X-Complaints-To: | newsadmin AT xtra DOT co DOT nz |
X-Trace: | news.xtra.co.nz 969182876 203.96.152.26 (Sun, 17 Sep 2000 21:27:56 NZST) |
NNTP-Posting-Date: | Sun, 17 Sep 2000 21:27:56 NZST |
To: | djgpp AT delorie DOT com |
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
Reply-To: | djgpp AT delorie DOT com |
Freeing (or deleting, in C++) the NULL pointer is not supposed to be done! Some DPMI servers ignore it, and some (such as DJGPP) will cause a SIGSEGV (segment violation) -- you're program will crash, and this is what you want to happen! If you ever try to free NULL, then you know you've got something wrong. In other words, yes, you should always check first to see if you have allocated something in the first place. I do not know what happens when you try to call a method (such as a destructor) from an object at location NULL. But you already know that you can never have a valid object at NULL in the first place! "Rafał Maj" <r_maj AT poczta DOT onet DOT pl> wrote in message news:8q1u4s$jh3$1 AT info DOT cyf-kr DOT edu DOT pl... > Hi, > what is supposed to happen when I'll try delete NULL: > int* x = NULL; > delete x; > Should I every time write if (x) delete x; ? > > And what about : > int* x=NULL; > delete []x; > > What will happen when I'll use my class, witch have destructor ? > myclass* x=NULL; > delete x; > delete []x; > > Will all above examples work same for other compilers then DJGPP ? > > Thanks, Rafal > > >
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |