www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/05/03/11:15:10

Message-ID: <3AF17523.3C2B6AB5@falconsoft.be>
Date: Thu, 03 May 2001 17:11:31 +0200
From: Tim Van Holder <tim DOT vanholder AT falconsoft DOT be>
Organization: Falcon Software NV
X-Mailer: Mozilla 4.77 [en] (X11; U; Linux 2.2.16-3 i686)
X-Accept-Language: en, nl-BE, nl
MIME-Version: 1.0
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Odp: Deleting after strdup
References: <9crage$5td$1 AT info DOT cyf-kr DOT edu DOT pl> <9crerk$mct$1 AT nets3 DOT rz DOT RWTH-Aachen DOT DE> <9crgf3$qr5$1 AT info DOT cyf-kr DOT edu DOT pl>
Lines: 23
NNTP-Posting-Host: 194.78.64.238
X-Trace: 988902661 reader1.news.skynet.be 43053 194.78.64.238
X-Complaints-To: abuse AT skynet DOT be
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Rafal Maj wrote:
> 
> So  both delete s; and delete[] s; are wrong ? I know that delete is C++
> style, but since char* has no destructor, I think that delete or delete[]
> will work for this type same as free(). Am I right ?
> 
No - neither the C++ nor the C standard say that new and malloc()
allocate
memory the same way. So you can't use free() to free memory allocated by
new, nor can you use delete to free memory allocated by malloc().

In practice, many implementations of new and delete (including the ones
in
the GNU library) use malloc and free internally.  But there's no
guarantee
this will stay that way, and it certianly isn't portable to make that
assumption.

-- 
Tim Van Holder - Falcon Software N.V.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
This message was posted using plain text. I do not endorse any
products or services that may be hyperlinked to this message.

- Raw text -


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