3 ms·
You're supposed to know that bitfields undergo promotion as they were small integers, even if they are declared to be something like unsigned int. Therefore, c
by kazinator 7mo ago
You're supposed to know that bitfields undergo promotion as they were small integers, even if they are declared to be something like unsigned int.
Therefore, convert the values before operating on them:
u1 = ((uint64_t) bf.uf1) << 20;
u2 = ((uint64_t) bf.uf2) << 20;
- tyfighter 7mo agoI just can agree with any interpretation of the article's code that believes programmers should desire silent sign extension when everything about the expression and data types involved is explicitly written to avoid signedness. At the end of the day, programming languages should naturally express intent and not rely on memorization of surprise. Here, I believe that Microsoft correctly employed principle of least surprise, and that ultimately the spec is broken and because of the amount of code in existence just can't be fixed.
- kazinator 7mo agoI completely agree that C's promotion behavior of unsigned types narrower than int going to int is wonky to a certain extent. However, introducing nonconforming exceptions to that behavior for bit fields doesn't help things. It just breaks correctly written code intended to be portable.