Two arguments to calloc

前端 未结 5 1235
一整个雨季
一整个雨季 2020-12-29 21:39

Why does calloc take two arguments instead of one like malloc?

Specifically, since there is no difference between (or is there?) between th

5条回答
  •  无人及你
    2020-12-29 22:06

    I believe that malloc is guaranteed to return an area of memory which is aligned according to the coarsest requirement that would be compatible with the size indicated by the second argument. For example, if the system requires alignment of 2 and 4-byte integers, and the second argument is 10, the returned pointer must be aligned on a two-byte boundary; if the second argument were 12, the pointer would be aligned on a four-byte boundary. I suspect that in practice many systems will align all returned pointers to the largest possibly-required boundary, regardless of size, but I don't think it's required except for calloc.

提交回复
热议问题