4 ms·
Even plain `COUNTOF(ptr)` is wrong, unless `ptr` is an array.
by firethief 7y ago
Even plain `COUNTOF(ptr)` is wrong, unless `ptr` is an array.
- MaulingMonkey 7y ago-Werror-sizeof-pointer-div Or in C++: #include <type_traits> template < typename T, std::size_t N > constexpr std::size_t count_of(const T (&)[N]) { return N; } #define COUNTOF(a) std::integral_constant<std::size_t, count_of(a)>::value (C++03 friendly versions are entirely possible, but left as an exercise to the reader)