diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2014-12-19 02:23:26 -0500 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2014-12-19 02:23:26 -0500 |
commit | 943b06329075865e4453a90f83afcbcfb2151965 (patch) | |
tree | 4b12072e943dcc4a5e542a7c8439cfe5f5460ba6 /src/nvim/macros.h | |
parent | 5df8bf077bc69eab4e660dc09026878adcf54bb8 (diff) | |
parent | 478c99c128df506479b37d7ffbd1adee3134607f (diff) | |
download | rneovim-943b06329075865e4453a90f83afcbcfb2151965.tar.gz rneovim-943b06329075865e4453a90f83afcbcfb2151965.tar.bz2 rneovim-943b06329075865e4453a90f83afcbcfb2151965.zip |
Merge pull request #1663 from philix/array_size
Define and use the ARRAY_SIZE macro
Diffstat (limited to 'src/nvim/macros.h')
-rw-r--r-- | src/nvim/macros.h | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/nvim/macros.h b/src/nvim/macros.h index 215ad3a1f7..7dd8120d09 100644 --- a/src/nvim/macros.h +++ b/src/nvim/macros.h @@ -152,4 +152,12 @@ # define RESET_BINDING(wp) (wp)->w_p_scb = FALSE; (wp)->w_p_crb = FALSE +/// Calculate the length of a C array. +/// +/// This should be called with a real array. Calling this with a pointer is an +/// error. A mechanism to detect many (though not all) of those errors at compile +/// time is implemented. It works by the second division producing a division by +/// zero in those cases (-Wdiv-by-zero in GCC). +#define ARRAY_SIZE(arr) ((sizeof(arr)/sizeof((arr)[0])) / ((size_t)(!(sizeof(arr) % sizeof((arr)[0]))))) + #endif // NVIM_MACROS_H |