简体   繁体   中英

Architectures with 2-bytes (or more) atomic endianness

Until recently, I thought that by specifying if an architecture is either big-endian or little-endian we would cover most systems (except middle-endian but these systems are not very common). But then, I read that the endianness "atomics" can be greater than bytes so that these system :

  • little endian with 1 byte atomic
  • little endian with 2 bytes atomic

will encode integers in different ways.

Question: How common systems with atomics equal or greater than two are?

Additional questions

  • Can the atomic size depends on the type of integer (for example different atomics for uint32_t and uint64_t )?
  • Do I have the guarantee that a char is always 1-byte long even on system with 2-bytes endianness atomics?

If you need to worry about the particular native byte order of your machine, you can use functions such as ntohl() and ntohs() , or just read one byte at a time.

There isn't any guarantee that char is exactly 8 bits wide (see <limits.h> to check the number), but char is guaranteed to be at least 8 bits wide (so that a char[] can hold a UTF-8 string) and sizeof(char) is guaranteed to be 1. If you need an exact 8-bit-wide type, use uint8_t .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM