C++ the meaning of getting size of a array -
here macro getting array size
#define array_size(array) \ (sizeof( array ) / (sizeof( array[0] ) * (sizeof( array ) != sizeof(void*) || sizeof( array[0] ) <= sizeof(void*)))
i think (sizeof( array ) / (sizeof( array[0] )) enough size of array.
i guess part
(sizeof( array[0] ) * (sizeof( array ) != sizeof(void*) || sizeof( array[0] ) <= sizeof(void*))
is avoid whole thing divided zero, explain?
thanks in advance.
cheers,
multiplying sizeof array[0]
in divisor by
(sizeof( array ) != sizeof(void*) || sizeof( array[0] ) <= sizeof(void*))
makes divisor 0 if
sizeof array == sizeof(void*)
and
sizeof array[0] > sizeof(void*)
in cases, division 0 during compilation, cause compilation fail.
these checks attempt detect arguments pointers (be result of array-to-pointer conversion or not), since 1 can't know how large "array" pointer points using quotient.
it fails if other pointer types have different sizes void*
, , doesn't detect pointers things not larger void*
s. more harm lulling author in false sense of security.