From: "Rafal Maj" Newsgroups: comp.os.msdos.djgpp Subject: Odp: Deleting after strdup Date: Thu, 3 May 2001 13:47:46 +0200 Organization: Academic Computer Center CYFRONET AGH Lines: 25 Message-ID: <9crgf3$qr5$1@info.cyf-kr.edu.pl> 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> NNTP-Posting-Host: d-94-53-03.cyfronet.krakow.pl X-Trace: info.cyf-kr.edu.pl 988890403 27493 149.156.1.163 (3 May 2001 11:46:43 GMT) X-Complaints-To: news AT cyf-kr DOT edu DOT pl NNTP-Posting-Date: Thu, 3 May 2001 11:46:43 +0000 (UTC) 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 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 ? Użytkownik Hans-Bernhard Broeker w wiadomości do grup dyskusyjnych napisał:9crerk$mct$1 AT nets3 DOT rz DOT RWTH-Aachen DOT DE... > Rafal Maj wrote: > > Sorry for newbie question... after char* s = strdup(...); I should use > > delete[] s; ? > > No. free(s). strdup() is a C function, not a C++ one, so it uses the > C style of memory allocation. > > > or is it safe to use char *s = strdup(org); ? > > Read it up in the docs. If they don't say you can pass in a NULL > without harm, then you shouldn't. > > > -- > Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de) > Even if all the snow were burnt, ashes would remain.