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]

 



On Mon, Apr 27, 2015 at 10:56:30AM -0700, Junio C Hamano wrote:

> Elia Pinto <gitter.spiros@xxxxxxxxx> writes:
> 
> > This is the second version of this patch.  It had not been
> > discussed before. In the second version, I just tried to clarify
> > the comment in the commit. I resend it just in case you missed
> 
> I do not recall seeing it before.  No discussion usually means no
> interest, so I'll see what happens this time on the list for a few
> days before picking it up.

I'm in favor of any method for improving compile-time bug-checking,
provided that:

  1. It does not carry a maintenance cost that spreads throughout the
     code base (e.g., here the cost is localized to making ARRAY_SIZE a
     bit more complex, but callers do not have to care about the extra
     checking).

  2. It gracefully degrades when using older compilers (i.e., we can
     fall back to the existing ARRAY_SIZE definition when the magic
     builtin is not available).

I think this is OK for both points. It would be nice if we could
auto-detect the presence of the builtin without using autoconf. I think
most git developers do not use autoconf at all, and the feature does not
help much if nobody turns it on. Is there a __GNUC__ or similar
feature-test macro we could use for this?

> > +#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.

Agreed on the naming (modulo the "not" from your follow-on email). Also,
should it be in ALL_CAPS like the other added macros? We are slightly
inconsistent about that in our code-base.

-Peff
--
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]