From 3c857900fe9a7eff87aa4fbe6e7b80ba602ad2bd Mon Sep 17 00:00:00 2001 From: Felipe Oliveira Carvalho Date: Sat, 13 Dec 2014 11:10:19 -0300 Subject: Define and use the ARRAY_SIZE macro A similar macro is defined in the Linux kernel [1]. To refactor the code I used a slightly modified Coccinelle script I found in [2]. ```diff // Use the macro ARRAY_SIZE when possible // // Confidence: High // Copyright: (C) Gilles Muller, Julia Lawall, EMN, DIKU. GPLv2. // URL: http://www.emn.fr/x-info/coccinelle/rules/array.html // Options: -I ... -all_includes can give more complete results @@ type T; T[] E; @@ - (sizeof(E)/sizeof(*E)) + ARRAY_SIZE(E) @@ type T; T[] E; @@ - (sizeof(E)/sizeof(E[...])) + ARRAY_SIZE(E) @@ type T; T[] E; @@ - (sizeof(E)/sizeof(T)) + ARRAY_SIZE(E) @n@ identifier AS,E; @@ - #define AS(E) ARRAY_SIZE(E) @@ expression E; identifier n.AS; @@ - AS(E) + ARRAY_SIZE(E) ``` `spatch --in-place --sp-file array_size.cocci -I src/ -I build/include/ -I build/src/nvim/auto/ src/nvim/*.c` [1] http://lxr.free-electrons.com/source/include/linux/kernel.h#L54 [2] http://www.emn.fr/z-info/coccinelle/rules/#macros --- src/nvim/indent_c.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/indent_c.c') diff --git a/src/nvim/indent_c.c b/src/nvim/indent_c.c index 6648a9f7c6..d6101357e3 100644 --- a/src/nvim/indent_c.c +++ b/src/nvim/indent_c.c @@ -303,7 +303,7 @@ static int cin_isinit(void) for (;; ) { int i, l; - for (i = 0; i < (int)(sizeof(skip) / sizeof(char *)); ++i) { + for (i = 0; i < (int)ARRAY_SIZE(skip); ++i) { l = (int)strlen(skip[i]); if (cin_starts_with(s, skip[i])) { s = cin_skipcomment(s + l); -- cgit