Re: [PATCH v2] git-compat-util.h: implement a different ARRAY_SIZE macro for for safely deriving the size of array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Junio C Hamano <gitster@xxxxxxxxx> writes:

>> +#if SUPPORT__BUILTIN_TYPES_COMPATIBLE_P
>> +/* &arr[0] degrades to a pointer: a different type from an array */
>> +#define _array_size_chk(arr)						\
>> +	BUILD_ASSERT_OR_ZERO(!__builtin_types_compatible_p(typeof(arr), \
>> +							typeof(&(arr)[0])))
>> +#else
>> +#define _array_size_chk(arr) 0
>> +#endif
>
> Wouldn't there be a more sensible name?  _chk does not tell us
> anything about what is being checked, and the only thing this name
> gives us is "what uses it" (i.e. it is some magic used by array-size
> and does not say what it checks and what for).
>
> I think you are checking arr is an array and not a pointer.  Perhaps
> "#define is_an_array(arr)" or something along that line may be a
> more descriptive name for it.
>
> I doubt the leading underscore is particularly a good idea, though.

And "is_an_array(arr)" is probably not quite a good name, as that
sounds as if it would give 1 and adding it to sizeof(x)/sizeof(x[0])
does not make sense.  barf_if_not_an_array() is what the macro does.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]