From 85921c9d25bc4f3e737e36f93a27947f3b27a363 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Tue, 12 May 2015 11:15:11 +0300 Subject: [PATCH] Add ARRAY_SIZE() helper macro There are many scenarios where it is convenient to have a helper to evaluate the number of elements in an array. Having this helper in a common place helps avoid duplicated code. Change-Id: I05e9513bca756675483276cb6ae777c487f5a949 Signed-off-by: Johan Hedberg --- include/misc/util.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/misc/util.h b/include/misc/util.h index 838b770f08f..78d685fc07c 100644 --- a/include/misc/util.h +++ b/include/misc/util.h @@ -42,6 +42,8 @@ Misc utilities usable by nanokernel, microkernel, and application code. extern "C" { #endif +#define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0])) + #ifndef _ASMLANGUAGE /* round "x" up/down to next multiple of "align" (which must be a power of 2) */