Portable code - bits per char

前端 未结 4 1444
夕颜
夕颜 2020-12-09 02:02

I know that the C/C++ standards only guarantee a minimum of 8 bits per char, and that theoretically 9/16/42/anything else is possible, and that therefore all sites

相关标签:
4条回答
  • 2020-12-09 02:41

    You can normally safely assume that files will have 8 bit bytes, or if not, that 8 bit byte files can be converted to a zero padded native format by a commonly-used tool. But it is much more dangerous to assume that CHAR_BIT == 8. Currently that is almost always the case, but it might not always be the case in future. 8 bit access to memory is increasingly a bottleneck.

    0 讨论(0)
  • 2020-12-09 02:44

    use limits.h

    CHAR_BIT

    http://www.cplusplus.com/reference/clibrary/climits/

    also, when you want to use exactly a given size, use stdint.h

    0 讨论(0)
  • 2020-12-09 02:53

    For example, many DSP have CHAR_BIT greater than or equal to 16.

    0 讨论(0)
  • 2020-12-09 02:58

    At least, similar to the integer size in 64bit architectures, future platforms may use a wider char, with more bits. ASCII characters might become obsolete, replaced by unicode. This might be a reason so be cautious.

    0 讨论(0)
提交回复
热议问题