Std :: byte on odd platforms

Having carefully read the message about the tragedy in C ++, reading the message that it std::bytewas added in C ++ 17. I have some problems as an initial reading, since it uses unsigned charso that it can avoid complications with strict alias rules.

My biggest problem: how does it work on platforms where CHAR_BITnot 8? I worked on platforms where CHAR_BIT- 16 or 32 (usually DSP). Given that it is std::bytedesigned to work with "byte-oriented access to memory," and most people understand bytes to indicate an octet (rather than the size of the base character type), how this will work for people who expect it to be addressed continuously 8 bits of memory?

I already see people who simply assume that it CHAR_BITis 8 (and not in the evening, knowing that it CHAR_BITexists ...). The type called std::byteis likely to lead to even more confusion with people.


I suppose I expected them to introduce a type that allows sequential addressing / access to sequential octets for all cases. There are many octet-oriented protocols where it would be useful to have a library or type guaranteed access to memory one octet at a time on all platforms, regardless of what CHAR_BITis equal on that platform.

I definitely understand that I want it to be well-specified that something is used as a sequence of bytes rather than a sequence of characters, but this does not seem to be as useful as many other things can be.

+6
1

, std::byte "- ", , ( ), , , 8- ?

- , , .

, , - , . CHAR_BIT == 8. , .

  • .
  • char, signed char unsigned char .

- , , , , . , , , , .

, : , . , , , ():). , , .


, :

, ", ".

+13

Source: https://habr.com/ru/post/1016205/


All Articles