[PATCH] array_length, array_end macros for internal use

Florian Weimer fweimer@redhat.com
Sat Oct 21 20:42:00 GMT 2017


On 10/21/2017 08:10 PM, Paul Eggert wrote:
> Thanks, this is a good thing to write a macro for. A couple of comments:
> 
> The Emacs internals use the name ARRAYELTS for the same concept. I 
> recall that the name was discussed at some length when the macro was 
> introduced. "length" is perhaps not the best word to use here, since 
> array_length ("foo") != strlen ("foo").

I didn't want to use array_size because of the potential confusion with 
sizeof.

> And capitalization is 
> appropriate when a macro cannot be written as a function. So I suggest 
> the name ARRAYELTS, or something like it.

glibc has not followed this style for some time (see libc_hidden_def, 
__libc_lock_lock etc.), and the C++ version (if we need it) will be 
written as a function anyway.

>> +#define array_end(var) &(var)[array_length (var)]
> 
> We haven't felt the need for such a macro in Emacs.

I saw a couple of uses in stdio-common, so I added it.

> If there's need in 
> glibc, the definiens should be parenthesized so that (mis?)uses like (& 
> ARRAYEND (var)->firstmember) are handled properly.

Thanks, fixed in my local version.

Florian



More information about the Libc-alpha mailing list