What is the difference between passing sbrk() an intptr_t vs int in C
It seems to have no impact on the functionality of sb开发者_运维问答rk, but in sbrk()'s documentation it says that it requires an intptr_t parameter.
It works (or at least seems to work) when passing an int type as a parameter.
This is in regular C.
intptr_t
changes size depending on the architecture. int
may or may not change size depending on the architecture- that is, if you are on 64bit, then intptr_t
MUST be 64bits, whereas int
may be 32bits.
As long as the right header is included, you're not passing an int
to sbrk()
. The value you are passing is converted to intptr_t
according to C promotion rules. These rules are terribly subtle so you should at least know they exist and avoid invoking them in corner cases.
As a consequence, do not expect something spectacular such as a crash, when you pass sbrk
something that looks to you like an int
, even if intptr_t
is different from int
on your platform, as long as the header that provides sbrk()
's prototype is included.
精彩评论