Hi Lennart, On 2023-08-27 02:00, Alejandro Colomar wrote: > Hi Lennart, Branden, > > On 2023-08-26 21:36, Lennart Jablonka wrote: >> 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? > > A quotation of ISO C would be interesting here. Preferably C17. > > I certainly remember ISO C talking about the number of elements in an > array. While I wouldn't be surprised to learn that it uses the term > 'size' when it's being more specific, I don't recall it from the top > of my head.
Self correction: it talks about elements in an array, but not necessarily about the number of it. And here's a quote where ISO C says that the size of an array is the value delimited by []: <https://port70.net/%7Ensz/c/c11/n1570.html#6.7.6.2p1> Confusingly enough, when it talks about sizeof(), it let's you think that the size of an array could also mean its size in bytes. ISO C should probably reword one of those. <https://port70.net/%7Ensz/c/c11/n1570.html#6.5.3.4p2> Cheers, Alex -- <http://www.alejandro-colomar.es/> GPG key fingerprint: A9348594CE31283A826FBDD8D57633D441E25BB5
OpenPGP_signature
Description: OpenPGP digital signature