summaryrefslogtreecommitdiff
path: root/n
diff options
context:
space:
mode:
authorschodet2006-05-07 23:23:52 +0000
committerschodet2006-05-07 23:23:52 +0000
commit4de16295a25423691fb9ba9eddcf6c9bf16d8d48 (patch)
tree338a9bd06bb0b2c903db822906fb9e0e2b87af2f /n
parentacf7840edf430d36ec01ad7ddbe98a7e490ba215 (diff)
Ajout de UTILS_COUNT.
Diffstat (limited to 'n')
-rw-r--r--n/avr/modules/utils/utils.h11
1 files changed, 7 insertions, 4 deletions
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 */