Is `reinterpret_cast <char *> (reinterpret_cast <uintptr_t> (& ch) + 1) == & ch + 1` guaranteed?

I am writing alignment-dependent code and am completely surprised that there is no standard function test if the given pointer is correctly aligned.

It seems that most of the code on the Internet is used to (long)ptreither reinterpret_cast<uintptr_t>(ptr)check for alignment, and I also used them, but I am wondering if the cast pointer is compatible with the integral type as standard compatible.

Is there any system that makes this statement here?

char ch[2];
assert(reinterpret_cast<char*>(reinterpret_cast<uintptr_t>(&ch[0]) + 1)
       == &ch[1]);
+4
source share
1 answer

To answer the question in the title: No.

: - Pr1me 16- . 12- , 2 ( 16- ). - 16- . A char * (, , void *) . , 0, 8 ( ). A uintptr_t uint48_t uint64_t. 1 .

, , , "", .

, , ++ Pr1me, , , . , .

+4

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


All Articles