delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/09/10/17:32:02

From: "Rafał Maj" <r_maj AT poczta DOT onet DOT pl>
Newsgroups: comp.os.msdos.djgpp
Subject: strdup() with delete[]
Date: Sun, 10 Sep 2000 23:18:07 +0200
Organization: Academic Computer Center CYFRONET AGH
Lines: 21
Message-ID: <8pgtns$sja$1@info.cyf-kr.edu.pl>
NNTP-Posting-Host: d-94-53-20.cyfronet.krakow.pl
X-Trace: info.cyf-kr.edu.pl 968620604 29290 149.156.1.180 (10 Sep 2000 21:16:44 GMT)
X-Complaints-To: news AT cyf-kr DOT edu DOT pl
NNTP-Posting-Date: 10 Sep 2000 21:16:44 GMT
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.00.2615.200
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

All memory allocated like
  char* s = new char[100];
should be deleted using :
  delete s[];
right ?

And what about allocation done with strdup() :
  char* s = strdup("test");
should I use then delete s[];  OR  delete s;  ?

=============
Is this correct :
    char *s;
     if (/*...*/) s=strdup(S);  else  { s=new char[2];  s[0]=ch;
 s[1]=NULL; }
    delete s[];

Thanks,
Rafal


- Raw text -


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