Converting a non-`void` pointer to `uintptr_t` and vice-versa

前端 未结 2 469
轻奢々
轻奢々 2020-12-17 14:44

There are two related C standard rules:

C99 standard, 6.3.2.3:

A pointer to void may be converted to or from a pointer to any i

2条回答
  •  误落风尘
    2020-12-17 15:08

    I wouldn't risk it. The standard makes it abundantly clear what is allowed and what is not allowed.

    Writing uintptr_t s = (uintptr_t)(void*)p; signals to a reader of your code that you know what you're doing.

提交回复
热议问题