C++ Logo

std-discussion

Advanced search

Re: Is it valid use reinterpret_cast to form pointer to object?

From: language.lawyer_at <language.lawyer_at_[hidden]>
Date: Tue, 1 Aug 2023 15:10:37 +0500
> Can you clarify your question please? Are you asking about this example
>
> alignas(T) std::byte storage[sizeof(T)];
> T *ptr = ::new (&storage) T;
> foo(reinterpret_cast<T*>(&storage));
>
> or
>
> alignas(T) std::byte storage[sizeof(T)];
> foo(reinterpret_cast<T*>(&storage));

Is there much difference, when `reinterpret_cast<T*>(&storage)` is considered?

Received on 2023-08-01 10:10:43