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 :
will encode integers in different ways.
Question: How common systems with atomics equal or greater than two are?
Additional questions
uint32_t
and uint64_t
)?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.