C++ Logo

std-discussion

Advanced search

Re: Fixing common reinterpret_cast design patterns

From: sdkrystian <sdkrystian_at_[hidden]>
Date: Sat, 20 Jul 2019 20:25:09 -0400
It is - see http://eel.is/c++draft/expr.static.cast#13 and http://eel.is/c++draft/expr.addThe cast will leave the pointer value unchanged. That means, when the addition is done, it is still pointing to the int object, which will result in a pointer past the end. Modifying it will result in UB.Sent from my Samsung Galaxy smartphone.
-------- Original message --------From: Lyberta via Std-Discussion <std-discussion_at_[hidden]> Date: 7/20/19 16:34 (GMT-05:00) To: sdkrystian via Std-Discussion <std-discussion_at_[hidden]> Cc: Lyberta <lyberta_at_[hidden]> Subject: Re: [std-discussion] Fixing common reinterpret_cast design patterns sdkrystian via Std-Discussion:> I have been working on some wording to change the following things with reinterpret_cast:- allow casting to char*, unsigned char* and std::byte* to access the object representation of an object, and- allow casting from char*, unsigned char* and std::byte* to an object pointer type T, where the pointer being casted is a pointer to an array or first element thereof providing storage to an object of type TThese are very common design patterns that are often used, and they currently have undefined behavior. I would like to get a sense of if this would be something that you all would like to see. Please provide any feedback or suggestions 😊> > The first case is not UB:https://stackoverflow.com/questions/16260033/reinterpret-cast-between-char-and-stduint8-t-safe

Received on 2019-07-20 19:27:08