From: Junio C Hamano <gitster@pobox.com>
To: Elia Pinto <gitter.spiros@gmail.com>
Cc: git@vger.kernel.org, peff@peff.net
Subject: Re: [PATCH v3] git-compat-util.h: implement a different ARRAY_SIZE macro for for safely deriving the size of array
Date: Thu, 30 Apr 2015 10:41:30 -0700 [thread overview]
Message-ID: <xmqqd22l1pkl.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <1430397854-28908-1-git-send-email-gitter.spiros@gmail.com> (Elia Pinto's message of "Thu, 30 Apr 2015 14:44:14 +0200")
Elia Pinto <gitter.spiros@gmail.com> writes:
> +#if defined(__GNUC__) && (__GNUC__ >= 3)
> +# if GIT_GNUC_PREREQ(3, 1)
> + /* &arr[0] degrades to a pointer: a different type from an array */
> +# define BARF_IF_IS_NOT_AN_ARRAY(arr) \
> + BUILD_ASSERT_OR_ZERO(!__builtin_types_compatible_p(typeof(arr), \
> + typeof(&(arr)[0])))
> +# else
> +# define BARF_IF_IS_NOT_AN_ARRAY(arr) 0
> +# endif
> +#endif
> +/*
> + * ARRAY_SIZE - get the number of elements in a visible array
> + * <at> x: the array whose size you want.
> + *
> + * This does not work on pointers, or arrays declared as [], or
> + * function parameters. With correct compiler support, such usage
> + * will cause a build error (see the build_assert_or_zero macro).
> + */
> +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]) + BARF_IF_IS_NOT_AN_ARRAY(x))
> +
> #define bitsizeof(x) (CHAR_BIT * sizeof(x))
>
> #define maximum_signed_value_of_type(a) \
Hmmmmmmmm.
CC ws.o
ws.c: In function 'parse_whitespace_rule':
ws.c:46:3: error: unknown type name 'typeof'
for (i = 0; i < ARRAY_SIZE(whitespace_rule_names); i++) {
^
$ gcc --version
gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There
is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.
next prev parent reply other threads:[~2015-04-30 17:41 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-30 12:44 [PATCH v3] git-compat-util.h: implement a different ARRAY_SIZE macro for for safely deriving the size of array Elia Pinto
2015-04-30 17:20 ` Junio C Hamano
2015-04-30 17:41 ` Junio C Hamano [this message]
2015-04-30 17:44 ` Jeff King
2015-04-30 17:54 ` Junio C Hamano
2015-04-30 17:59 ` Junio C Hamano
2015-04-30 18:19 ` Jeff King
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=xmqqd22l1pkl.fsf@gitster.dls.corp.google.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=gitter.spiros@gmail.com \
--cc=peff@peff.net \
/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.