I\'ve just noticed that the pointers passed to delete
can be const
qualified while those passed to free
cannot. That is really a surprise
One difference is that free
is a library function and you must match the parameter type. When free
was added to the C language there was no const
keyword, so that couldn't even be considered.
In C++ delete p
is a statement handled by the compiler. It can do whatever the language designer wants it to, including not consider if the object pointed to is const
or not.
Philosophically speaking, the delete
statement doesn't modify the object, it just makes it go away.