On 5/4/24 2:30 PM, Paul Eggert wrote: >> But, I think the next POSIX revision has <endian.h> like Glibc which I >> prefer. > > If the past is any guide, an advantage of the C23 version is that in > the long run it is likely to be more portable. POSIX is an extension > of C.
True. But I don't think C23 has the conversion macros: /* big endian 32 to host. */ uint32_t be32toh (uint32_t); /* little endian 32 to host. */ uint32_t le32toh (uint32_t); like the next POSIX revision has and I am a fan of. I assume the addition of <endian.h> was inspired by glibc's implementation. glibc seems to have extended <sys/endian.h> from the BSDs by adding those conversion macros. Since <sys/endian.h> seems resonably portable, that could do the bulk of the work for non glibc systems. GCC even has these: $ echo | gcc -dM -E - | grep 'ENDIAN' #define __ORDER_LITTLE_ENDIAN__ 1234 #define __FLOAT_WORD_ORDER__ __ORDER_LITTLE_ENDIAN__ #define __ORDER_PDP_ENDIAN__ 3412 #define __ORDER_BIG_ENDIAN__ 4321 #define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__ Collin