From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: Elia Pinto <gitter.spiros@gmail.com>, git@vger.kernel.org
Subject: Re: [PATCH v2] git-compat-util.h: implement a different ARRAY_SIZE macro for for safely deriving the size of array
Date: Tue, 28 Apr 2015 01:42:37 -0400 [thread overview]
Message-ID: <20150428054237.GI24580@peff.net> (raw)
In-Reply-To: <xmqq1tj5xxo1.fsf@gitster.dls.corp.google.com>
On Mon, Apr 27, 2015 at 10:56:30AM -0700, Junio C Hamano wrote:
> Elia Pinto <gitter.spiros@gmail.com> 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
prev parent reply other threads:[~2015-04-28 5:42 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-27 13:11 [PATCH v2] git-compat-util.h: implement a different ARRAY_SIZE macro for for safely deriving the size of array Elia Pinto
2015-04-27 17:56 ` Junio C Hamano
2015-04-27 18:11 ` Junio C Hamano
2015-04-28 5:42 ` Jeff King [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150428054237.GI24580@peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=gitter.spiros@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.