From a69f4fb067ec22b95741e37efe355fb1106fefd2 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Mon, 7 Jul 2025 08:44:05 -0400 Subject: prelude: Move countof() here from bfs.h countof() will likely be in the C2Y standard. Link: https://www.open-std.org/JTC1/SC22/WG14/www/docs/n3469.htm Link: https://thephd.dev/c2y-hitting-the-ground-running --- src/bfs.h | 5 ----- src/prelude.h | 9 +++++++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/bfs.h b/src/bfs.h index 70a7282..ab96bf5 100644 --- a/src/bfs.h +++ b/src/bfs.h @@ -58,11 +58,6 @@ extern const char bfs_ldlibs[]; // Fundamental utilities -/** - * Get the length of an array. - */ -#define countof(...) (sizeof(__VA_ARGS__) / sizeof(0[__VA_ARGS__])) - /** * False sharing/destructive interference/largest cache line size. */ diff --git a/src/prelude.h b/src/prelude.h index 3b1c4e5..1663af6 100644 --- a/src/prelude.h +++ b/src/prelude.h @@ -88,6 +88,15 @@ #endif // !C23 +// Future C standard backports + +/** + * Get the length of an array. + * + * https://www.open-std.org/JTC1/SC22/WG14/www/docs/n3469.htm + */ +#define countof(...) (sizeof(__VA_ARGS__) / sizeof(0[__VA_ARGS__])) + // Feature detection // https://clang.llvm.org/docs/LanguageExtensions.html#has-attribute -- cgit v1.2.3