git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Jeff King <peff@peff.net>
Date
Apr 30, 2015, 17:44 UTC
Message-ID
<20150430174440.GC21800@peff.net>
In-Reply-To
<xmqqd22l1pkl.fsf@gitster.dls.corp.google.com>
On Thu, Apr 30, 2015 at 10:41:30AM -0700, Junio C Hamano wrote:
Show 28 quoted lines
> 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
> [...]
> 
> 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.

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.

-Peff
Previous: Junio C HamanoNext: Junio C Hamano
Message 4 of 7 in “git-compat-util.h: implement a different ARRAY_SIZE macro for for safely deriving the size of array”
  1. git-compat-util.h: implement a different ARRAY_SIZE macro for for safely deriving the size of arrayElia Pinto, Apr 30, 2015
  2. Junio C HamanoApr 30, 2015
  3. Junio C HamanoApr 30, 2015
  4. Jeff KingApr 30, 2015
  5. Junio C HamanoApr 30, 2015
  6. Junio C HamanoApr 30, 2015
  7. Jeff KingApr 30, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.