Securing an integer in void pointer

In this article I refer to the entire index and indexes: reinterpret_cast

(conversion in the opposite direction in the opposite direction is not guaranteed, the same pointer can have several integer representations)

Do I understand correctly that the standard does not guarantee the following:

intptr_t x = 5; 
void* y = reinterpret_cast<void*>(x);
assert(x == reinterpret_cast<intptr_t>(y));

Can anyone confirm?

+4
source share
2 answers

Your interpretation is correct. The relevant clause of the standard is [expr.reinterpret.cast] / 5 in C ++ 17:

. , ( ) ; . [. , 6.7.4.3, . - ]

, ( ), , ; , ", ". cppreference, , .

+3

, . intptr_t , , , , , pigeonhole , void*.

0

Source: https://habr.com/ru/post/1691567/


All Articles