From 1ac794cb618fea55db81cc697f46442bf70469d8 Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Fri, 24 Apr 2020 18:37:10 +0530 Subject: [PATCH] include: Add array_size() macro Getting array size of a dynmaic array can be very handy hence this patch. Signed-off-by: Anup Patel Reviewed-by: Alistair Francis --- include/sbi/sbi_types.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/sbi/sbi_types.h b/include/sbi/sbi_types.h index 153c1850..0952d5c8 100644 --- a/include/sbi/sbi_types.h +++ b/include/sbi/sbi_types.h @@ -78,6 +78,8 @@ typedef unsigned long physical_size_t; const typeof(((type *)0)->member) * __mptr = (ptr); \ (type *)((char *)__mptr - offsetof(type, member)); }) +#define array_size(x) (sizeof(x) / sizeof((x)[0])) + #define MAX(a, b) ((a) > (b) ? (a) : (b)) #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define CLAMP(a, lo, hi) MIN(MAX(a, lo), hi)