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

This is a discussion on Bad to use New & Malloc in the same C++ source? within the C++ Programming forums, part of the General Programming Boards category; Would it be considered bad style to use both the new and malloc statements in the same C++ file? It's ...

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

    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 08: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
    32,854
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 04: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, 09: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-02-2004, 12:36 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21