From ebefa8b890fb25a1190225df0ab5a73237309c54 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Fri, 21 Sep 2018 07:12:24 +0200 Subject: [PATCH] Refactor, simplify helper macro Signed-off-by: Joachim Nilsson --- src/editline.c | 4 ++-- src/editline.h | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/editline.c b/src/editline.c index 9aa8e10..30f64f1 100644 --- a/src/editline.c +++ b/src/editline.c @@ -1933,12 +1933,12 @@ static el_status_t el_bind_key_in_map(int key, el_keymap_func_t function, el_key el_status_t el_bind_key(int key, el_keymap_func_t function) { - return el_bind_key_in_map(key, function, Map, ARRAY_ELEMENTS(Map)); + return el_bind_key_in_map(key, function, Map, NELEMS(Map)); } el_status_t el_bind_key_in_metamap(int key, el_keymap_func_t function) { - return el_bind_key_in_map(key, function, MetaMap, ARRAY_ELEMENTS(MetaMap)); + return el_bind_key_in_map(key, function, MetaMap, NELEMS(MetaMap)); } /** diff --git a/src/editline.h b/src/editline.h index d41eddf..d11b6e6 100644 --- a/src/editline.h +++ b/src/editline.h @@ -57,8 +57,10 @@ #define MEM_INC 64 #define SCREEN_INC 256 -/* http://stackoverflow.com/questions/1598773/is-there-a-standard-function-in-c-that-would-return-the-length-of-an-array/1598827#1598827 */ -#define ARRAY_ELEMENTS(arr) ((sizeof(arr)/sizeof(0[arr])) / ((size_t)(!(sizeof(arr) % sizeof(0[arr]))))) +/* From The Practice of Programming, by Kernighan and Pike */ +#ifndef NELEMS +#define NELEMS(array) (sizeof(array) / sizeof(array[0])) +#endif /* ** Variables and routines internal to this package.