4 ms·
>this also means that you can use it to print the “low” bits of an int when trying to just read the low-end bits as well, such as by using printf("%w8d", 0xFEE)
by xeeeeeeeeeeenu 5y ago
>this also means that you can use it to print the “low” bits of an int when trying to just read the low-end bits as well, such as by using printf("%w8d", 0xFEE);
Note that this happens to work when the argument's type is int (or anything smaller) only because of default argument promotions. For larger types it will cause undefined behaviour. So, for example, printf("%w8d", 0x1LL) is not legal.
- nynx 5y agoInsane that it’s this easy to cause undefined behavior. Forgot what size a “long long” is on your arch when writing a print statement? Undefined behavior.
- tux3 5y agoMultiplying unsigned shorts is famously (?) undefined behavior on most platforms. They get promoted to int, and the result overflows. https://stackoverflow.com/questions/33732489/ https://stackoverflow.com/questions/33732489/
- vlovich123 5y agoThis seems like one of the more innocuous ones that’s automatically caught by compiler warnings. Admittedly projects have to turn that on and fix warnings (or build with errors) and not all do. The standard should really mandate that certain kind of warnings today should just be unconditional compiler errors.