delete [] or without [] 
Author Message
 delete [] or without []

Why does the compiler not complain about this?

int * blah = new int[100];

delete blah;

it should be
delete [] blah;
of course...



Wed, 05 Oct 2005 23:17:35 GMT  
 delete [] or without []



Quote:
> Why does the compiler not complain about this?

> int * blah = new int[100];

> delete blah;

> it should be
> delete [] blah;
> of course...

Because, in the general case, with separate compilation
of translation units and dynamically loaded code, it is
not possible to reliably detect such errors at compile
time.  It would, of course, be possible to diagnose the
simpler cases such as your example, but that would not
solve the general problem and could promote sloppiness
on the part of naive programmers.

If you want a lot of checks along those lines, there is
a cross-module checker for C++ available from Gimpel
Software.  See:  http://www.gimpel.com  .

--
-Larry Brasfield
(address munged, s/sn/h/ to reply)



Thu, 06 Oct 2005 00:54:18 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Can't delete rows from a table in SQL Server 2000 without a primary key

2. How must I open Recordset, without deleting records?

3. Copy Registry Entry Without Deleting Old Entry ~ function call parameters not correct

4. Copy Registry Entry Without Deleting Old Entry ~ function call parameters not correct

5. Q: Hiding a tree control item without deleting

6. CRecordset::Delete without field exchange

7. ASSERTion on delete? (delete [] bla bla)

8. how to delete a DELETED directory ?

9. Q: CRecordSet::Delete() doesn't really delete??

10. CRecordset::Delete does not delete my record!

11. delete[] instead of delete

12. delete and delete []

 

 
Powered by phpBB® Forum Software