1
0
forked from 0ad/0ad

Make ARRAY_SIZE(pointer) complain in GCC, not just in MSVC.

The ArraySizeDeducer trick has worked since at least GCC 4.4, so it's
fine to rely on it now.

This was SVN commit r16218.
This commit is contained in:
Ykkrosh 2015-01-24 17:35:25 +00:00
parent de25e536c3
commit 67956f969e

View File

@ -314,17 +314,6 @@ switch(x % 2)
// number of array elements
//
#if GCC_VERSION
// The function trick below does not work in GCC. Instead use the old fashioned
// divide-by-sizeof-element. This causes problems when the argument to
// ARRAY_SIZE is a pointer and not an array, but we will catch those when we
// compile on something other than GCC.
#define ARRAY_SIZE(name) (sizeof(name) / (sizeof((name)[0])))
#else
// (function taking a reference to an array and returning a pointer to
// an array of characters. it's only declared and never defined; we just
// need it to determine n, the size of the array that was passed.)
@ -335,7 +324,6 @@ template<typename T, size_t n> char (*ArraySizeDeducer(T (&)[n]))[n];
// pointer is passed, which can easily happen under maintenance.)
#define ARRAY_SIZE(name) (sizeof(*ArraySizeDeducer(name)))
#endif // GCC_VERSION
// C99-style __func__
// .. newer GCC already have it