diff options
author | Campbell Barton <ideasman42@gmail.com> | 2014-05-18 17:50:44 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-05-18 17:51:59 +0400 |
commit | 2a49bf35f08752cadf998a05867c4244378b4c57 (patch) | |
tree | 9910a962886a80301d5bf02d66ae354046819548 /source/blender/blenlib/BLI_utildefines.h | |
parent | 07e8096c63a35af3331aae7781643ca103dd1bdf (diff) |
Add ARRAY_SIZE macro to check fixed size arrays
Diffstat (limited to 'source/blender/blenlib/BLI_utildefines.h')
-rw-r--r-- | source/blender/blenlib/BLI_utildefines.h | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_utildefines.h b/source/blender/blenlib/BLI_utildefines.h index f70befddc4d..20ed2e06714 100644 --- a/source/blender/blenlib/BLI_utildefines.h +++ b/source/blender/blenlib/BLI_utildefines.h @@ -361,6 +361,15 @@ (((tot) - (index)) - (tot_delete)) * sizeof(*(arr))); \ } (void)0 +/* assuming a static array */ +#ifdef __GNUC__ +# define ARRAY_SIZE(arr) \ + ((sizeof(struct {int isnt_array : ((void *)&(arr) == &(arr)[0]);}) * 0) + \ + (sizeof(arr) / sizeof(*(arr)))) +#else +# define ARRAY_SIZE(x) sizeof(arr) / sizeof(*(arr)) +#endif + /* Warning-free macros for storing ints in pointers. Use these _only_ * for storing an int in a pointer, not a pointer in an int (64bit)! */ #define SET_INT_IN_POINTER(i) ((void *)(intptr_t)(i)) |