Is CHAR_BIT ever > 8?

TMS320C28x DSP from Texas Instruments has a byte with 16 bits. Documentation for the compiler specifies CHAR_BIT as 16 on page 101. This appears to be a modern processor (currently being sold), compilers supporting C99 and C++03.

C/C++: Force Bit Field Order and Alignment

No, it will not be fully-portable. Packing options for structs are extensions, and are themselves not fully portable. In addition to that, C99 ยง6.7.2.1, paragraph 10 says: “The order of allocation of bit-fields within a unit (high-order to low-order or low-order to high-order) is implementation-defined.” Even a single compiler might lay the bit field out … Read more

max value of integer

In C, the language itself does not determine the representation of certain datatypes. It can vary from machine to machine, on embedded systems the int can be 16 bit wide, though usually it is 32 bit. The only requirement is that short int <= int <= long int by size. Also, there is a recommendation … Read more

Divide by 10 using bit shifts?

Editor’s note: this is not actually what compilers do, and gives the wrong answer for large positive integers ending with 9, starting with div10(1073741829) = 107374183 not 107374182. It is exact for smaller inputs, though, which may be sufficient for some uses. Compilers (including MSVC) do use fixed-point multiplicative inverses for constant divisors, but they … Read more