Why / when to use `intptr_t` for type-casting in C?

前端 未结 4 1263
长发绾君心
长发绾君心 2020-11-28 03:13

I have a question regarding using intptr_t vs. long int. I\'ve observed that incrementing memory addresses (e.g. via manual pointer arithmetic) dif

4条回答
  •  盖世英雄少女心
    2020-11-28 04:02

    intptr_t is a new invention, created after 64-bit and even 128-bit memory addresses were imagined.

    If you ever need to cast a pointer into an integer type, always use intptr_t. Doing anything else will cause unnecessary problems for people who need to port your code in the future.

    It took a long time to iron out all of the bugs with this in programs like Mozilla/Firefox when people wanted to compile it on 64-bit Linux.

提交回复
热议问题