Thread: Bad to use New & Malloc in the same C++ source?

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    204

    Bad to use New & Malloc in the same C++ source?

    Would it be considered bad style to use both the new and malloc statements in the same C++ file? It's a small file, less than 120 lines of code. No classes are used and there are only two #include headers, <iostream> and <fstream>.
    Last edited by thetinman; 03-31-2007 at 07:16 AM. Reason: details

  2. #2
    Registered User Noir's Avatar
    Join Date
    Mar 2007
    Posts
    218
    It's cool if you don't mix new/delete and malloc/free, but you'll get confused about what pointer was created with new and what pointer was created with malloc. That makes working on your code harder, regardless of how short it is.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,662
    Unless it's some ancient C++ which is being maintained, you should be using new/delete in all your C++ code.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to build, run Boland C++ 6 source file via VS2005?
    By userpingz in forum C++ Programming
    Replies: 2
    Last Post: 05-21-2009, 03:25 AM
  2. Debug into Source
    By lehe in forum C++ Programming
    Replies: 4
    Last Post: 02-18-2009, 10:45 AM
  3. malloc and realloc
    By odysseus.lost in forum C Programming
    Replies: 3
    Last Post: 05-27-2005, 08:44 AM
  4. malloc() & address allocation
    By santechz in forum C Programming
    Replies: 6
    Last Post: 03-21-2005, 09:08 AM
  5. malloc always setting length of 8?
    By Zarkhalar in forum C++ Programming
    Replies: 7
    Last Post: 08-01-2004, 11:36 PM