C++ Logo

std-discussion

Advanced search

Re: A lifetime question about start_lifetime_as

From: Yongwei Wu <wuyongwei_at_[hidden]>
Date: Tue, 8 Jul 2025 22:35:41 +0800
Thanks for the confirmation. I guessed so but was not very sure.

On Tue, 8 Jul 2025 at 22:20, Brian Bi <bbi5291_at_[hidden]> wrote:

> On Tue, Jul 8, 2025 at 9:57 AM Yongwei Wu via Std-Discussion <
> std-discussion_at_[hidden]> wrote:
>
>> Assume I am working on a little-endian machine only. Is the following
>> code undefined behaviour?
>>
>> uint32_t data = 0x40400000;
>> auto f = *std::start_lifetime_as<float>(&data);
>>
>
> It's fine as long as `sizeof(float) <= sizeof(uint32_t)`. See
> https://eel.is/c++draft/obj.lifetime#2
>
>
>>
>> If it is not, is the data variable still accessible now?
>>
>
> No. The `data` object's lifetime has ended because its storage has been
> reused. https://eel.is/c++draft/basic.life#2.5
>

Received on 2025-07-08 14:35:56