TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
C++ Coding Standard

Rule:  PCA#001Checked automatically with code checker

Synopsis:Use new and delete instead of malloc, calloc, realloc, free and cfree
Severity Level:1
Category:Parts of C++ to Avoid


In C malloc, realloc and free are used to allocate memory dynamically on the heap. This may lead to conflicts with the use of the new and delete operators in C++. It is dangerous to:

  • invoke delete for a pointer obtained via malloc/realloc,
  • invoke malloc/realloc for objects having constructors,
  • invoke free for anything allocated using new.

Thus, avoid whenever possible the use of malloc, realloc and free. See also [OAL#006] and [OAL#007].

Note that the C library function "strdup" implicitly allocates memory that must be freed using "free". It's better not to use this function in C++.

Literature References:
Ellemtel Rule 50
ISC++ Rec. 13.1