From dc1685ca25567fe75c8d50c825fb0303fbb66fac Mon Sep 17 00:00:00 2001 From: Zachary T Welch Date: Mon, 16 Nov 2009 03:29:30 -0800 Subject: move ARRAY_SIZE macro to types.h The ARRAY_SIZE macro was defined in several target files, so move it to types.h. This patch also removes two other identical macros: DIM (from jtag.h) and asizeof (from arm11.h). --- src/helper/types.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/helper/types.h') diff --git a/src/helper/types.h b/src/helper/types.h index 8f6283b5..96a923b8 100644 --- a/src/helper/types.h +++ b/src/helper/types.h @@ -60,6 +60,16 @@ typedef bool _Bool; #define __stringify(s) #s +/** + * Compute the number of elements of a variable length array. + * + * const char *strs[] = { "a", "b", "c" }; + * unsigned num_strs = ARRAY_SIZE(strs); + * + */ +#define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x))) + + /** * Cast a member of a structure out to the containing structure. * @param ptr The pointer to the member. -- cgit v1.2.3