When is uintptr_t preferred over intptr_t?

前端 未结 4 708
粉色の甜心
粉色の甜心 2021-02-05 09:27

Given the requirement that I need to store the value of a \"generic\" pointer in a struct and have no interest in the pointed-at memory itself, I find it more semantically corre

4条回答
  •  自闭症患者
    2021-02-05 10:31

    That sounds very strange, since it's going to require casts. A void * in C has the huge advantage that it converts to/from other object pointer types without casts, which is way clean.

    That said uintptr_t might make sense if you want to do things to the bits of the pointer that you can't do as sensibly with a signed integer (such as shifting them to the right, for instance).

提交回复
热议问题