Unable to delete [] char* in MSVC 6.0

Discussion in 'C++' started by Ramiro Barbosa, Jr., Oct 8, 2004.

  1. 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
    Ramiro Barbosa, Jr., Oct 8, 2004
    #1
    1. Advertising

  2. Ramiro Barbosa, Jr.

    Sharad Kala Guest

    "Ramiro Barbosa, Jr." <> wrote in message
    >
    > 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
    Sharad Kala, Oct 8, 2004
    #2
    1. Advertising

  3. Ramiro Barbosa, Jr.

    Sharad Kala Guest


    > 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
    Sharad Kala, Oct 8, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. wwj
    Replies:
    7
    Views:
    526
  2. h79
    Replies:
    2
    Views:
    410
  3. wwj
    Replies:
    24
    Views:
    2,462
    Mike Wahler
    Nov 7, 2003
  4. Ben Pfaff
    Replies:
    5
    Views:
    454
    Tristan Miller
    Jan 17, 2004
  5. lovecreatesbeauty
    Replies:
    1
    Views:
    993
    Ian Collins
    May 9, 2006
Loading...

Share This Page