Date: Tue, 8 Jul 2025 10:20:04 -0400
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
>
> Best regards,
>
> Yongwei
>
> --
> Yongwei Wu
> URL: http://wyw.dcweb.cn/
> --
> Std-Discussion mailing list
> Std-Discussion_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/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
>
> Best regards,
>
> Yongwei
>
> --
> Yongwei Wu
> URL: http://wyw.dcweb.cn/
> --
> Std-Discussion mailing list
> Std-Discussion_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
>
-- *Brian Bi*
Received on 2025-07-08 14:20:24