On Feb 18, 11:36 pm, chameleon <cham_...@hotmail.comwrote:
free(0);
is there a problem with this?
....
This, work with delete a;, so I ask if work with free(a); too.
Because my code is full of:
if (a) { free(a); a = 0; }
Yes, there's a problem: free() is ONLY to be used with memory
allocated from malloc(). delete() is ONLY to be used to free up memory
allocated via one of the new() operators.
Also, it is legal to call free(0), according to the standard. Some old
code does a check (like the above) which only calls free(x) if x is
non-0, because historically (before the standard) some C libs would
crash if passed 0. According to the C++ standard, though, passing 0 to
free() or delete is a no-op.