Re: delete[]

Discussion in 'C++' started by Andrey Tarasevich, Jul 17, 2003.

  1. VoluMetrix wrote:
    > Using vc6 sp5 the following code fails during delete, due to the base
    > class having a virtual destructor.
    > ...


    It is a known defect of the implementation. Your sample code meets just
    the requirements that should be met to reproduce the behavior: an
    attempt to delete a zero-sized array of polymorphic objects. It is
    perfectly legal in C++, but MSVC++ 6 will choke on it at run-time.

    A simple investigation will reveal the reason for the crash: the code
    attempts to access virtual destructor through the VMT of the first
    element in the array, which results in a crash, since there is no first
    element in your case. Looks like Microsoft in their MSVC++ 6
    implementation decided to support polymorphic deletion of arrays (which
    is not a part of C++ standard). It would make a legitimate MS-specific
    extension and someone would probably find it useful, but they managed to
    screw up along the way and came up with an implementation that produces
    a crash in a perfectly standard compliant code.

    --
    Best regards,
    Andrey Tarasevich
    Brainbench C and C++ Programming MVP
     
    Andrey Tarasevich, Jul 17, 2003
    #1
    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. Sandeep Grover

    delete on delete !

    Sandeep Grover, Jul 12, 2003, in forum: C++
    Replies:
    19
    Views:
    624
    Chris \( Val \)
    Jul 22, 2003
  2. HeroOfSpielburg
    Replies:
    1
    Views:
    393
    Alf P. Steinbach
    Aug 6, 2003
  3. 0to60
    Replies:
    4
    Views:
    313
    Jerry Coffin
    Dec 19, 2003
  4. Mathieu Malaterre

    delete NULL, what about delete[] NULL

    Mathieu Malaterre, Aug 17, 2004, in forum: C++
    Replies:
    2
    Views:
    3,840
    Mathieu Malaterre
    Aug 17, 2004
  5. Jef Driesen
    Replies:
    1
    Views:
    505
    Gernot Frisch
    Jan 19, 2005
Loading...

Share This Page