Nevertheless, it's what the standard says. C99 6.3.1.4: When a finite
value of real floating type is converted to an integer type other than
_Bool, the fractional part is discarded (i.e. the value is truncated
toward zero). If the value of the integral part cannot be represented
by the integer type, the behavior is undefined.
By definition any double you're allowed to convert to an unsigned char
doesn't need the "and".
I acknowledge that the type system is full of holes (“C++ is not safe”) and the standard gives you leeway, but I’ve never before witnessed a cast to an integer type not yielding some value in range for that integer type. And even clang does provide such here, on x86 and amd64.
I have to also read our spec to see what we are supposed to return here also.
The “workaround” of casting to int first doesn’t seem any better defined than casting directly to char, given a double that doesn’t fit in int either.