X-Git-Url: https://review.openocd.org/gitweb?a=blobdiff_plain;f=src%2Fhelper%2Ftypes.h;h=03ab5f0c2edd03ef2c8afa168c1b9f8343c54691;hb=0a9daddc2e20d9ff5053a9faf3e1ec11fd600c73;hp=a8753c5f149115c539e2e39d3eeb07256344f172;hpb=f0ce88b3af9a6090ac986160950d66317de5087e;p=openocd.git diff --git a/src/helper/types.h b/src/helper/types.h index a8753c5f14..03ab5f0c2e 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. @@ -73,6 +83,15 @@ typedef bool _Bool; (type *)( (char *)__mptr - offsetof(type,member) );}) +/** + * Rounds @c m up to the nearest multiple of @c n using division. + * @param m The value to round up to @c n. + * @param n Round @c m up to a multiple of this number. + * @returns The rounded integer value. + */ +#define DIV_ROUND_UP(m, n) (((m) + (n) - 1) / (n)) + + /* DANGER!!!! here be dragons! * * Leave these fn's as byte accesses because it is safe