From b3e9e62599532050fc776c5e8f076915b56c2235 Mon Sep 17 00:00:00 2001 From: David Faulkner Date: Fri, 7 Aug 2026 23:40:47 -0500 Subject: Import official C23 code examples for Modern C (Jens Gustedt, 2024) - Add official C source files, Makefile, c23-fallback.h, and LICENSE - Update README.md with study mirror notice --- endianness.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 endianness.c (limited to 'endianness.c') diff --git a/endianness.c b/endianness.c new file mode 100644 index 0000000..ec589d7 --- /dev/null +++ b/endianness.c @@ -0,0 +1,19 @@ +#include +#include + +typedef union unsignedInspect unsignedInspect; +union unsignedInspect { + unsigned val; + unsigned char bytes[sizeof(unsigned)]; +}; +unsignedInspect twofold = { .val = 0xAABBCCDD, }; + +int main(void) { + printf("value is 0x%.08X\n", twofold.val); + for (size_t i = 0; i < sizeof twofold.bytes; ++i) + printf("byte[%zu]: 0x%.02hhX\n", i, twofold.bytes[i]); + unsigned val = 0xAABBCCDD; + unsigned char* valp = (unsigned char*)&val; + for (size_t i = 0; i < sizeof val; ++i) + printf("byte[%zu]: 0x%.02hhX\n", i, valp[i]); +} -- cgit v1.2.3