Unable to delete [] char* in MSVC 6.0

  • Thread starter Ramiro Barbosa, Jr.
  • Start date
R

Ramiro Barbosa, Jr.

All,

I was wondering why this causes a debug assertion failure in MSVC6.0/EE/SP5:

void main()
{
char* p = "HELLO";
delete [] p;
}

Any ideas?

Thank you!

-Ramiro
 
S

Sharad Kala

Ramiro Barbosa said:
I was wondering why this causes a debug assertion failure in MSVC6.0/EE/SP5:

void main()
{
char* p = "HELLO";
delete [] p;

Because you only delete memory obtained through new.

Sharad
 
S

Sharad Kala

I was wondering why this causes a debug assertion failure in MSVC6.0/EE/SP5:

void main()

int main(), don't believe VC6 that accepts void main().
{
char* p = "HELLO";

Also note that the memory pointed by p is non-modifiable (AFAIK, many Unix
compilers place it in some read-only-memory location but this is
implementation dependent). Attempting to modify it is undefined behavior.
Also note that calls to new and new [] operators should be properly matched
by a corresponding call to delete and delete [] operators respectively.
Failing to do so is another cause of Undefined Behavior.

Sharad
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top