mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-02-23 08:13:56 -04:00
AP_Common: simplify ARRAY_SIZE
This rolls back to the simpler version of ARRAY_SIZE. The more complex one helps catching bugs when we use pointers when we are expecting an array, but can't stand arrays with 0 elements. I'm not aware of bugs it actually caught on ArduPilot, although it did for me in other projects. I think this is better than having a separate "_SIMPLE" version of the macro and spread its usage... the trend is just to use the simpler version anyway.
This commit is contained in:
parent
660da5aaea
commit
57ee0e29f6
@ -71,13 +71,7 @@
|
||||
#define LOWBYTE(i) ((uint8_t)(i))
|
||||
#define HIGHBYTE(i) ((uint8_t)(((uint16_t)(i))>>8))
|
||||
|
||||
template <typename T, size_t N>
|
||||
char (&_ARRAY_SIZE_HELPER(T (&_arr)[N]))[N];
|
||||
|
||||
template <typename T>
|
||||
char (&_ARRAY_SIZE_HELPER(T (&_arr)[0]))[0];
|
||||
|
||||
#define ARRAY_SIZE(_arr) sizeof(_ARRAY_SIZE_HELPER(_arr))
|
||||
#define ARRAY_SIZE(_arr) (sizeof(_arr) / sizeof(_arr[0]))
|
||||
|
||||
// simpler ARRAY_SIZE which can handle zero elements
|
||||
#define ARRAY_SIZE_SIMPLE(_arr) (sizeof(_arr)/sizeof(_arr[0]))
|
||||
|
Loading…
Reference in New Issue
Block a user