🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.help
Article #50780

forgetting [] when deleting arrays in diff vers of gcc

#50780
From: Alan Ezust
Date: Mon, 23 Aug 1993 19:43
38 lines
2192 bytes

In the comp.lang.C++ faq it says that forgetting to use the [] in the
delete[] ptr for deleting dynamically allocated arrays is a bad thing, as
it will usually result in a heap corruption. 

For old versions of g++, the delete[] is not even supported, so you *have* 
to use :
  delete [size] ptr
for pointers to arrays, and this means you gotta know the size of your
array when you delete it.

I'm modifying a HUGE program which just uses
  delete ptr
for pointers to arrays and objects alike. It does not give me segmentation
faults or anything, and I am compiling this under g++ 1.4.

I am wondering if, given a newer version of gcc, using the delete (no
square brackets) statement on pointers to arrays will cause heap
corruption, or if gcc is smart enough to delete arrays properly when the
[] is omitted...

And if the behaviour varies depending on which version of GCC is used,
I am curious to know which versions will allow you to omit the [] and
which ones will not.


Thanks in advance.

This info is needed because I am trying to port this c++ program which
compiles on g++ 1.4 but gives me segmentation faults for reasons unknown
when I compile under newer versions of gcc, and I am wondering if this
is the cause of the segmentation faults.

-- 
| Alan Ezust           ezust@iro.umontreal.ca      Montreal, Quebec, Canada |
|---------- Universite de Montreal    Departement d'informatique -----------|
        "Non-determinism means never having to say you're wrong."
Technical Details
Message-ID: <1993Aug23.194318.3569@IRO.UMontreal.CA>
Path: arc1-ca.pugleaf.net!gmd.de!xlink.net!sol.ctr.columbia.edu!howland.reston.ans.net!europa.eng.gtefsd.com!uunet!newsflash.concordia.ca!sifon!CC.UMontreal.CA!IRO.UMontreal.CA!ezust

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11318c,53997e09e076f4eb,start
X-Google-Attributes: gid11318c,public
X-Google-ArrivalTime: 1993-08-23 13:58:42 PST
Newsgroups: gnu.gcc.help
Path: arc1-ca.pugleaf.net!gmd.de!xlink.net!sol.ctr.columbia.edu!howland.reston.ans.net!europa.eng.gtefsd.com!uunet!newsflash.concordia.ca!sifon!CC.UMontreal.CA!IRO.UMontreal.CA!ezust
From: ezust@IRO.UMontreal.CA (Alan Ezust)
Subject: forgetting [] when deleting arrays in diff vers of gcc
Message-ID: <1993Aug23.194318.3569@IRO.UMontreal.CA>
Sender: news@IRO.UMontreal.CA
Organization: Universite de Montreal, Canada
Distribution: gnu
Date: Mon, 23 Aug 1993 19:43:18 GMT
Lines: 38