开发者

what happens if malloc (STL allocator, etc)requested to allocate 0 bytes [duplicate]

This question already has answers here: 开发者_StackOverflow社区 Closed 11 years ago.

Possible Duplicate:

what does malloc(0) return ?

Does it return zero pointer? Is the behavior standardized?

How about STL allocator?

I googled it, but couldn't pinpoint the answer I was looking for.

EDIT: The linked question doesn't explain STL allocator.

I have another relevant question. What happens if one tries to deallocate zero pointer?

allocator.deallocate(0, 1);


malloc(0) may either return 0 or it may return a unique address (which shall not be accessed) -- the C89 and C99 Standards allow either behavior but do not mandate either one. (Bad design for a standard and I objected when I was on X3J11 but that's how it is.)

BTW, this is a duplicate question: what does malloc(0) return?


Tested on Linux 2.6.34.7-66.fc13.x86_64, it returns a unique address.

I wouldn't try to dereference it though. :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜