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

Re: What's in git.git

From
Linus Torvalds <torvalds@osdl.org>
Date
Jun 25, 2006, 18:43 UTC
Message-ID
<Pine.LNX.4.64.0606251138580.3747@g5.osdl.org>
In-Reply-To
<20060625210724.934617c4.tihirvon@gmail.com>
On Sun, 25 Jun 2006, Timo Hirvonen wrote:
Show 5 quoted lines
> > 
> > I suspect that both could have been made to use NULL instead to indicate 
> > that no pointer exists.
> 
> I'll look into this.

An alternative is to really mark the char pointer structure members const. That is often the preferred thing to do, if usage allows it.

The biggest problem I've traditionally had with structure members that are "const char *" has ironically been that the standard C definition of "free()" is misdesigned.

"free()" should take a "const volatile void *", not just a "void *". As it is, you often have to cast things to free() just to avoid the warning about discarding qualifiers. Which is really sad.

It's perfectly valid to do something like
	struct xyzzy {
		const char *member;
		..
	};
	s->member = strdup(string);
	..
	free(s->member);
	free(s)
but sadly, that member free generates a (bogus) warning.

Of course, we should probably do a "xfree()" anyway, to match our "x[c|re]alloc()".

			Linus
Previous: Timo HirvonenNext: Junio C Hamano
Message 4 of 8 in “What's in git.git”
  1. Junio C HamanoJun 25, 2006
  2. Linus TorvaldsJun 25, 2006
  3. Timo HirvonenJun 25, 2006
  4. Linus TorvaldsJun 25, 2006
  5. Junio C HamanoJun 27, 2006
  6. Linus TorvaldsJun 27, 2006
  7. Johannes SchindelinJun 27, 2006
  8. Martin LanghoffJun 26, 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.