summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAnup Patel <[email protected]>2020-04-24 18:37:10 +0530
committerAnup Patel <[email protected]>2020-05-01 09:57:24 +0530
commit1ac794cb618fea55db81cc697f46442bf70469d8 (patch)
tree8ca947a95897977118ab1694458fb918459cd162 /include
parentf0eb503db4c14176f165ca067798b079571decda (diff)
include: Add array_size() macro
Getting array size of a dynmaic array can be very handy hence this patch. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Alistair Francis <[email protected]>
Diffstat (limited to 'include')
-rw-r--r--include/sbi/sbi_types.h2
1 files changed, 2 insertions, 0 deletions
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)