如果我正在编写 100% ANSI C 但在 .cpp 文件中编译,编译器会自动“优化”malloc 并免费调用 new 和 delete 吗?考虑到他们的差异,这甚至有意义吗?我不认为这是它的工作原理,但我的一个 friend 说这是发生了什么。
最佳答案
C++ 在 c.malloc
中非常具体:
The functions
calloc()
,malloc()
, andrealloc()
do not attempt to allocate storage by calling::operator new()
.The function
free()
does not attempt to deallocate storage by calling::operator delete()
.
关于c++ - C++ 编译器一般是 "optimize"malloc 和 free to new and delete 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53502688/