← Back to davo.co
summaryrefslogtreecommitdiffstats
path: root/array_or_struct.c
diff options
context:
space:
mode:
authorDavid Faulkner <[email protected]>2026-08-07 23:40:47 -0500
committerDavid Faulkner <[email protected]>2026-08-07 23:40:47 -0500
commitb3e9e62599532050fc776c5e8f076915b56c2235 (patch)
treeaf252346106a61b18cc6fc6fdbd32e962d096f1c /array_or_struct.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 'array_or_struct.c')
-rw-r--r--array_or_struct.c30
1 files changed, 30 insertions, 0 deletions
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 <stdio.h>
+
+#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;
+ }
+}