Any real example of reinterpret_cast changing a pointer value?

后端 未结 5 2325
灰色年华
灰色年华 2021-02-08 07:17

According to C++ Standard, a reinterpret_cast of a pointer T* to some other type pointer Q* can change or not change the pointer value dep

5条回答
  •  执笔经年
    2021-02-08 08:12

    I don't think the question is meaningfully different for C++ versus C pointer casts. From this answer I quote only one of the examples:

    The Eclipse MV series from Data General has three architecturally supported pointer formats (word, byte, and bit pointers), two of which are used by C compilers: byte pointers for char* and void*, and word pointers for everything else

    That suggests a reinterpret_cast(char*) could lose its sense of which character/byte in the word was being pointed at, making the operation irreversible.

提交回复
热议问题