delete for free(3)

A

Anuj

can i call delete for malloc() allocated memory?

--www.andr.ru

It will produce unpredictable results, often leading to program crash.
Though, I don't know the reason, I have read this in Scott Maeyer's
Effective C++
 
D

David Côme

<snip>

NO!!!!!!!!!!
Never call delete on memory wich have been allocated by malloc .
Never call free on memory wich have been allocated by new.

new <->delete
new[] <->delete[]
malloc <->free
 
J

Jack Klein

It will produce unpredictable results, often leading to program crash.

No, it will cause undefined behavior, which is a term defined by the
C++ language standard. That standard does not define the term
"unpredictable results".
Though, I don't know the reason, I have read this in Scott Maeyer's
Effective C++

The reason is that it causes undefined behavior. You break the rules
and you no longer have a C++ program.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,181
Messages
2,570,970
Members
47,537
Latest member
BellCorone

Latest Threads

Top