[prev in list] [next in list] [prev in thread] [next in thread]
List: git
Subject: Re: [PATCH v3] git-compat-util.h: implement a different ARRAY_SIZE macro for for safely deriving the
From: Jeff King <peff () peff ! net>
Date: 2015-04-30 18:19:01
Message-ID: 20150430181901.GA23431 () peff ! net
[Download RAW message or body]
On Thu, Apr 30, 2015 at 10:59:06AM -0700, Junio C Hamano wrote:
> Junio C Hamano <gitster@pobox.com> writes:
>
> > Jeff King <peff@peff.net> writes:
> >
> >> ISTR that you compile with "-std=c89". typeof was added in c99, I think
> >> (and was a GNU extension before that). I wonder if that is fooling the
> >> gcc version-check.
> >
> > Yeah, I think that is very likely.
>
> Yes. One workaround is to explicitly say that we accept the GNU
> extension in the source, perhaps.
>
> git-compat-util.h | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/git-compat-util.h b/git-compat-util.h
> index f1f8f23..7fad5aa 100644
> --- a/git-compat-util.h
> +++ b/git-compat-util.h
> @@ -62,8 +62,8 @@
> # if GIT_GNUC_PREREQ(3, 1)
> /* &arr[0] degrades to a pointer: a different type from an array */
> # define BARF_UNLESS_AN_ARRAY(arr) \
> - BUILD_ASSERT_OR_ZERO(!__builtin_types_compatible_p(typeof(arr), \
> - typeof(&(arr)[0])))
> + BUILD_ASSERT_OR_ZERO(!__builtin_types_compatible_p(__typeof__(arr), \
> + __typeof__(&(arr)[0])))
That seems like a reasonable fix, provided that other gcc-compatible
compilers implement the GNU-compatible name. I just tried with clang
3.5, and it seems to work fine.
And I was wrong about "typeof". It is not in C99 at all. So I think it
is really a matter of whether you are in the default "-std=gnu89" mode
or not, as to whether the compiler imports the "typeof" keyword, or if
it must be hidden in the compiler-reserved area (starting with "__").
-Peff
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic