读书人

malloc(0)的意义。解决办法

发布时间: 2012-03-08 13:30:13 作者: rapoo

malloc(0)的意义。
上次看到书上说malloc(0)会返回一个正确的指针,是为了任何两个分配的内存有不同的地址,但是看到c++ 对象模型时,上面又说这种机制是为了保证临时对象的行为的,不懂。到底意义何在,请高人指点。

[解决办法]

C/C++ code
来自C99的最权威的解释:If the size of the space requested is zero, the behavior is implementationdefined:either a null pointer is returned, or the behavior is as if the size were somenonzero value, except that the returned pointer shall not be used to access an object. 

读书人网 >C++

热点推荐