diff options
| author | David Faulkner <[email protected]> | 2026-08-07 23:40:47 -0500 |
|---|---|---|
| committer | David Faulkner <[email protected]> | 2026-08-07 23:40:47 -0500 |
| commit | b3e9e62599532050fc776c5e8f076915b56c2235 (patch) | |
| tree | af252346106a61b18cc6fc6fdbd32e962d096f1c /endianness.c | |
Import official C23 code examples for Modern C (Jens Gustedt, 2024)HEADupstream-importmain
- Add official C source files, Makefile, c23-fallback.h, and LICENSE
- Update README.md with study mirror notice
Diffstat (limited to 'endianness.c')
| -rw-r--r-- | endianness.c | 19 |
1 files changed, 19 insertions, 0 deletions
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 <stdio.h> +#include <inttypes.h> + +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]); +} |
