Introduce ARRAY_SIZE macro

Checked by `checkpatch`, and you know what? Not a bad thing
See https://github.com/gbdev/rgbds/pull/931#discussion_r738856724
This commit is contained in:
ISSOtm
2021-10-31 07:53:22 +01:00
parent b002d95459
commit 1a07391a97
2 changed files with 6 additions and 3 deletions

View File

@@ -89,4 +89,8 @@
#define STR(x) #x
#define EXPAND_AND_STR(x) STR(x)
// Obtaining the size of an array; `arr` must be an expression, not a type!
// (Having two instances of `arr` is OK because the contents of `sizeof` are not evaluated.)
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof *(arr))
#endif /* HELPERS_H */