From 4de16295a25423691fb9ba9eddcf6c9bf16d8d48 Mon Sep 17 00:00:00 2001 From: schodet Date: Sun, 7 May 2006 23:23:52 +0000 Subject: Ajout de UTILS_COUNT. --- n/avr/modules/utils/utils.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'n') diff --git a/n/avr/modules/utils/utils.h b/n/avr/modules/utils/utils.h index 6301505..e4e4c10 100644 --- a/n/avr/modules/utils/utils.h +++ b/n/avr/modules/utils/utils.h @@ -61,10 +61,10 @@ utils_delay_ms (double ms) /** Bound a value between MIN and MAX. */ #define UTILS_BOUND(v, min, max) \ do { \ - if (v < min) \ - v = min; \ - else if (v > max) \ - v = max; \ + if ((v) < (min)) \ + (v) = (min); \ + else if ((v) > (max)) \ + (v) = (max); \ } while (0) /** Return maximum of two values. */ @@ -76,4 +76,7 @@ utils_delay_ms (double ms) /** Absolute value. */ #define UTILS_ABS(v) ((v) > 0 ? (v) : -(v)) +/** Count the number of element in an array. */ +#define UTILS_COUNT(a) (sizeof (a) / sizeof ((a)[0])) + #endif /* utils_h */ -- cgit v1.2.3