www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/05/03/12:30:40

From: eins AT durchnull DOT de (Rudolf Polzer)
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>
X-newsgroup: comp.os.msdos.djgpp
X-realname: Rafal Maj
X-Ringtones: http://ringtones AT durchnull DOT de
X-Original: no
Message-ID: <slrn9f38qj.13h.eins@www42.t-offline.de>
User-Agent: slrn/0.9.6.3 (Linux)
Date: Thu, 3 May 2001 20:28:36 +0200
Lines: 21
NNTP-Posting-Host: 213.6.169.81
X-Trace: 988906242 news.freenet.de 25779 213.6.169.81
X-Complaints-To: abuse AT freenet DOT de
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Rafal Maj <maj_rafal AT poczta DOT onet DOT pl> 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 ?

Unfortunately not. Perhaps there is no impact in DJGPP, but the standard
forbids this.

Bjarne Stroustrup ('The C++ Programming Language') (no exact wording):
Allocating a pointer using new or new[] and deallocating it using
free() is asking for trouble.

Of course the other way round is not ok either.

If it works depends on your C++ library; if the new and delete operators
call malloc and free, what you are trying to do is safe. If not, it will
make trouble. So: do not do this!

-- 
#!/usr/bin/perl -w -- sequences
$0=++$|;for(;;){print-length$0;$0=~s/(.)\1*/$1.length$&/ge;}print"\n";

- Raw text -


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