← Back to davo.co
aboutsummaryrefslogtreecommitdiffstats
path: root/constexpr.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 /constexpr.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 'constexpr.c')
-rw-r--r--constexpr.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/constexpr.c b/constexpr.c
new file mode 100644
index 0000000..81bd929
--- /dev/null
+++ b/constexpr.c
@@ -0,0 +1,29 @@
+#include "c23-fallback.h"
+#include <math.h>
+#include <stdio.h>
+
+#if __is_identifier(constexpr)
+# error "constexpr is needed for this test"
+// really stop it
+# include "really stop useless compilation right now"
+#endif
+
+
+#define eatit(P) printf("" #P ": %p\n", &(P))
+
+[[__maybe_unused__]] static constexpr size_t size_max = (size_t)-1;
+
+[[__maybe_unused__]] constexpr long double π = 3.141'592'653'589'793'238'46;
+[[__maybe_unused__]] constexpr long double π² = π*π;
+
+[[__maybe_unused__]] constexpr div_t one = { .quot = 1, .rem = 0, };
+
+[[__maybe_unused__]] constexpr double E𝟏[2][2] = { {1, 0,}, {0, 1,}, };
+
+int main(void) {
+ eatit(size_max);
+ eatit(π);
+ eatit(π²);
+ eatit(one);
+ eatit(E𝟏);
+}