Thread: valgrind Mismatch free() / delete /

  1. #16
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Using delete on new[] is undefined, but that doesn't mean it won't work. It may or may not work, so it's not really a good demonstration of destructors firing or not. You may get different results depending on compiler and platform.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #17
    Nasal Demon Xupicor's Avatar
    Join Date
    Sep 2010
    Location
    Poland
    Posts
    179
    Yes, it's undefined behavior, I know. My point was not to show what will happen with destructors, but what might happen.

    On my system for example delete on new[]ed array will fire just one destructor, and free won't fire any.

  3. #18
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Well... again, the behavior might change. It might look fine on the OP's system. I get the point. Perhaps it would have been better if you showed some output of what could happen?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. using delete and free
    By Pulock2009 in forum C Programming
    Replies: 4
    Last Post: 09-10-2010, 09:20 AM
  2. New/delete vs malloc/free
    By KBriggs in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2009, 03:08 PM
  3. Replies: 17
    Last Post: 11-16-2006, 09:06 PM
  4. malloc & free in C vs. new & delete in C++
    By groberts1980 in forum C Programming
    Replies: 20
    Last Post: 10-17-2006, 10:00 PM
  5. free() or delete?
    By Trauts in forum C++ Programming
    Replies: 7
    Last Post: 05-14-2003, 04:20 PM

Tags for this Thread