When is uintptr_t preferred over intptr_t?

前端 未结 4 2076
甜味超标
甜味超标 2021-02-05 09:30

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:25

    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).

提交回复
热议问题