utils/macros: add countof

Rename ARR_COUNT to countof that is probably going to be defined by C2Y
in stdcountof.h (as a macro for _Countof) for convenience.

+ keep the ARR_COUNT for compatibility
This commit is contained in:
Martin Pulec
2026-01-07 08:49:16 +01:00
parent 74e5eab149
commit 951f9648d9

View File

@@ -3,7 +3,7 @@
* @author Martin Pulec <pulec@cesnet.cz>
*/
/*
* Copyright (c) 2014-2025 CESNET
* Copyright (c) 2014-2026 CESNET, zájmové sdružení právnických osob
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -61,7 +61,10 @@
#define SWAP(a, b) do { b ^= a; a ^= b; b ^= a; } while (0)
#define SWAP_PTR(a, b) do { void *tmp = (a); (a) = (b); (b) = tmp; } while(0)
#define ARR_COUNT(arr) (sizeof (arr) / sizeof (arr)[0])
#ifndef countof // defined in C2Y stdcountof.h
#define countof(arr) (sizeof (arr) / sizeof (arr)[0])
#endif
#define ARR_COUNT(arr) countof(arr)
#undef MIN
#define MIN(a,b) (((a)<(b))?(a):(b))