logoalt Hacker News

psyclobe04/23/20252 repliesview on HN

That’s super cool; c++ is always the sharpest tool in the drawer (and by virtue the funnest!)..

It’s too bad you still can’t cast a char to a uint8_t though in a constexpr expression.


Replies

lbhdc04/23/2025

This compiles in clang 21.1.2 with c++26.

    #include <cstdint>
    #include <print>

    constexpr uint8_t f(char ch) {
     return static_cast<uint8_t>(ch);
    }

    int main() {
     constexpr uint8_t r = f('a');
     std::print("{}", r);
    }
show 1 reply
vinkelhake04/23/2025

> It’s too bad you still can’t cast a char to a uint8_t though in a constexpr expression.

Uh, what? That has worked fine since the introduction of constexpr in C++11.

show 1 reply