Re: delete vs delete[]
- From: Alex Blekhman <xfkt@xxxxxxxxx>
- Date: Mon, 21 May 2007 19:28:19 +0300
Carl Daniel [VC++ MVP] wrote:
bob@xxxxxxxxxxxxxx wrote:I was just wondering why the compiler won't warn you when you try to
do this:
TCHAR *t = new TCHAR[20];
delete t;
A fair question - I can't see any reason why the compiler couldn't warn in a case like this. Of course, in real programs, there's likely to be a much greater distance between the allocation and the deallocation, which would make generating an error or warning considerably harder.
I think, it is because the task of a compiler is to check syntactical correctness of a code, while it's up to developer to check logical correctness. However, Team System edition of VC++ has handy "/analyze" compiler option, which besides other checks, attempts to detect new/delete mismatch. See, for example, warnings C6278, C6283.
Alex
.
- Follow-Ups:
- Re: delete vs delete[]
- From: Carl Daniel [VC++ MVP]
- Re: delete vs delete[]
- References:
- delete vs delete[]
- From: bob
- Re: delete vs delete[]
- From: Carl Daniel [VC++ MVP]
- delete vs delete[]
- Prev by Date: Re: C++ quirks - frustrated with secure CRT [long]
- Next by Date: Re: namespace trouble
- Previous by thread: Re: delete vs delete[]
- Next by thread: Re: delete vs delete[]
- Index(es):
Relevant Pages
|