bpo-35194: cjkcodec: check the encoded value is not truncated by izbyshev · Pull Request #10432 · python/cpython (original) (raw)
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The advantage of macros for the purpose of catching conversions changing the mathematical value is that (unsigned char)(c) == (c)
checks it for any integer type of c
. Note that mathematical values of both operands are never changed in this comparison, at least if we consider C99
-conforming compilers and don't take into account platforms where a byte is not 8-bit.
If we used a function instead, c
would always be converted to its parameter type. No matter what type we choose, even the widest one, the mathematical value of the argument can be changed (if not because of truncation, than because of conversions between signed and unsigned types). So I don't see how static inline functions can help in this particular issue. Macros may be ugly, but they may also be a powerful tool for specific tasks.