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 --- array_or_struct.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 array_or_struct.c (limited to 'array_or_struct.c') diff --git a/array_or_struct.c b/array_or_struct.c new file mode 100644 index 0000000..3190fe1 --- /dev/null +++ b/array_or_struct.c @@ -0,0 +1,30 @@ +#include + +#ifdef USE_STRUCT + typedef struct two two; + struct two { double e1; double e2; }; +# define FRST(X) ((X).e1) +# define SEC(X) ((X).e2) +#else + typedef double two[2]; +# define FRST(X) ((X)[0]) +# define SEC(X) ((X)[1]) +#endif + +void func0(void) { + for (two sp = { 1, 1, }; + FRST(sp) + SEC(sp) < 10; + FRST(sp) += SEC(sp)) { + printf("two values %g %g\n", FRST(sp), SEC(sp)); + SEC(sp) += (FRST(sp) + SEC(sp))/2; + } +} + +void func1(void) { + for (register two sp = { 1, 1, }; + FRST(sp) + SEC(sp) < 10; + FRST(sp) += SEC(sp)) { + printf("two values %g %g\n", FRST(sp), SEC(sp)); + SEC(sp) += (FRST(sp) + SEC(sp))/2; + } +} -- cgit v1.2.3