Finally, one-line endianness detection in the C preprocessor

In 30 years of C programming, I thought I’d seen everything. Well, every bizarre trick you could pull with the C preprocessor, anyway. I was wrong. Contemplate this: #include <stdint .h> #define IS_BIG_ENDIAN (*(uint16_t *)”\0\xff” < 0x100) That is magnificently awful. Or awfully magnificent, I'm not sure which. And it pulls off a combination of… Continue reading Finally, one-line endianness detection in the C preprocessor

Published
Categorized as Software