Quoth Alejandro Colomar:
The good news is that I like the implementation. I just don't like the
name. I have a sizeof_array() macro that does
#define sizeof_array(a) (sizeof(a) + must_be_array(a))
That is, it calculates the size in bytes that the array takes up in memory.
<https://github.com/shadow-maint/shadow/pull/762/commits/8d06d849dcb5f7041e048d866ec7ce6c1853245b>
For a macro that returns the number of elements in an array, I'd like a
name that cannot be confused with that at all. NELEMS(), NITEMS(),
array_count(), or lengthof() all seem better than array_size().
I'm not a fan of lengthof(), even if it's a proposal to ISO C, as so far
the term "length" was only the number of non-zero characters in a string,
and overloading it to mean the number of elements in an array would
similarly be a bad thing. At least it's not so confusing as size, though.
NITEMS() or NELEMS() seems the best choice to me.
I like both lengthof (as “length” is commonly used for the number
of elements in an array) and nelem (which is what Plan 9 uses).
I do wanna note that the term used by the C standard is “size” and
the term used by the C++ standard is “bound.” How about boundof?