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