Elektrine lite

← Feed

@manx@mastodon.online

Post #2636439

2026-04-07 12:25 UTC

@DanielaKEngert@hachyderm.io @andreasfertig@mas.to https://andreasfertig.com/blog/2025/04/the-correct-way-to-do-type-punning-in-cpp-the-second-act/ BROKEN CODE: bool ProcessData(std::span bytes) { ... ConfigValues* cfgValues = std::start_lifetime_as(bytes.data());

Replies (1)

  • @manx@mastodon.online 2026-04-07 12:57

    @DanielaKEngert@hachyderm.io @andreasfertig@mas.to std::start_lifetime_as is probably fine for doing what it was designed to do, i.e. working around type confusion in legacy C APIs (I know of examples in the audio field), or C-style allocation functions. However, people apparently like to also teach it as some kind of crude de-serialization primitive. Even the original paper advertises this use case, which frankly horrifies me: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2590r2.pdf ...

    Open ##2636440