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 --- euclid.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 euclid.h (limited to 'euclid.h') diff --git a/euclid.h b/euclid.h new file mode 100644 index 0000000..82fca4e --- /dev/null +++ b/euclid.h @@ -0,0 +1,24 @@ +#ifndef EUCLID_H +# define EUCLID_H 1 + +# include "c23-fallback.h" +# include +# include + +inline size_t gcd2(size_t a, size_t b) [[__unsequenced__]] { + assert(a <= b); /*@\label{gcd2-precondition}*/ + if (!a) return b; /*@\label{gcd2-bottom}*/ + size_t rem = b % a; /*@\label{gcd2-remainder}*/ + return gcd2(rem, a); /*@\label{gcd2-recurse}*/ +} + +inline size_t gcd(size_t a, size_t b) [[__unsequenced__]] { + assert(a); + assert(b); + if (a < b) + return gcd2(a, b); + else + return gcd2(b, a); +} + +#endif -- cgit v1.2.3