2 ms·
If you define in C/C++ a structure with bit fields, and you declare the bit fields as being either signed or unsigned, assigning the bit fields to a bigger inte
by adrian_b 2y ago
If you define in C/C++ a structure with bit fields, and you declare the bit fields as being either signed or unsigned, assigning the bit fields to a bigger integer, which is appropriately signed or unsigned, will perform an optimal sign extension or zero extension, as necessary, without having to write any expression.
When you need sign extension or zero extension for conversion between standard integer types, you have to write only the type casting operator.
Having to use any of the inefficient tricks presented in the parent article is necessary only when you do not declare the correct types for your variables.
- notepad0x90 2y agoI was think more about convenience than necessity.