首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

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

2012-03-08 
malloc(0)的意义。上次看到书上说malloc(0)会返回一个正确的指针,是为了任何两个分配的内存有不同的地址,但

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. 

热点排行