logoalt Hacker News

TuxSH04/24/20251 replyview on HN

You can't static_cast in this case; https://godbolt.org/z/a1bMbPcaj


Replies

lbhdc04/24/2025

You can use `std::bit_cast` to do that in constexpr contexts.

    constexpr auto f(uint8_t *x) {
      return std::bit_cast<char *>(x);
    }
https://godbolt.org/z/K3f9b9GGs
show 2 replies