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

Re: [PATCH] Fix git to be (more) ANSI C99 compliant.

From
Linus Torvalds <torvalds@osdl.org>
Date
Jun 18, 2006, 16:50 UTC
Message-ID
<Pine.LNX.4.64.0606180946090.5498@g5.osdl.org>
In-Reply-To
<1150609831500-git-send-email-octo@verplant.org>
On Sun, 18 Jun 2006, Florian Forster wrote:
>
> Using this patch I was able to build git with
> $ make CFLAGS="-Wall -Werror -ansi -pedantic -std=c99 -D_XOPEN_SOURCE=500 -D_BSD_SOURCE"
"-ansi -pedantic" is really not useful.
> While most of this patch fixes void-pointer arithmetic

This one I disagree with. Doing arithmetic on "void *" is _really_ useful, and I think most compilers end up supporting it either to be compatible with gcc, or just because it's hard to not do it.

It makes code a _lot_ cleaner.

In general, explicit casts are a sign of bad programming, and "void *" is there exactly to avoid it. And doing arithmetic on pointers is useful and fairly common, and if you accept void-pointer arithmetic, it avoids a lot of ugly and useless casts.

Show 9 quoted lines
> @@ -301,9 +301,9 @@ static void fill_line_map(struct commit 
>  				if (DEBUG)
>  					printf("map: i1: %d %d %p i2: %d %d %p\n",
>  					       i1, map[i1],
> -					       i1 != -1 ? blame_lines[map[i1]] : NULL,
> +					       (void *) (i1 != -1 ? blame_lines[map[i1]] : NULL),
>  					       i2, map2[i2],
> -					       i2 != -1 ? blame_lines[map2[i2]] : NULL);
> +					       (void *) (i2 != -1 ? blame_lines[map2[i2]] : NULL));

Gaah. This is another case of casting that I'm sure is technically correct, but that I wonder whether there is any machine that actually cares..

But at least in that case I suspect the cast _may_ be required due to different pointer representations.

		Linus
Previous: Junio C HamanoNext: Florian Forster
Message 10 of 15 in “Fix git to be (more) ANSI C99 compliant.”
  1. Fix git to be (more) ANSI C99 compliant.Florian Forster, Jun 18, 2006
  2. Timo HirvonenJun 18, 2006
  3. Thomas GlanzmannJun 18, 2006
  4. Florian ForsterJun 18, 2006
  5. Timo HirvonenJun 18, 2006
  6. Rene ScharfeJun 18, 2006
  7. Florian ForsterJun 18, 2006
  8. 0/7 Improve ANSI C99 complianceFlorian Forster, Jun 18, 2006
  9. Junio C HamanoJun 18, 2006
  10. Linus TorvaldsJun 18, 2006
  11. Florian ForsterJun 19, 2006
  12. Junio C HamanoJun 20, 2006
  13. Rene ScharfeJun 20, 2006
  14. Junio C HamanoJun 20, 2006
  15. Junio C HamanoJun 21, 2006

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.