简体   繁体   中英

What is the difference between passing sbrk() an intptr_t vs int in C

It seems to have no impact on the functionality of sbrk, 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM