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

Re: [PATCH 1/3] diff --stat: allow custom diffstat output width.

From
Linus Torvalds <torvalds@osdl.org>
Date
Sep 29, 2006, 06:17 UTC
Message-ID
<Pine.LNX.4.64.0609282307220.3952@g5.osdl.org>
In-Reply-To
<Pine.LNX.4.64.0609282252430.3952@g5.osdl.org>
On Thu, 28 Sep 2006, Linus Torvalds wrote:
Show 5 quoted lines
> 
> because the only reason strtoul() warns now is that C type-rules don't 
> allow the (obviously safe - but pointers migth have strange 
> representations) conversion of "char **" into "const char **", even though 
> "char *" can be converted into "const char *".
I phrased that badly. 

IF C pointer conversion allowed implicit addition of "const" past the top-most level, ANSI C would have just done "strtoul()" as

	unsigned long strtoul(const char *n, const char **p, int);

ie they could just have added the "const" not just to the first argument, and legact programs (without const) would still have worked fine.

But _because_ that's not how C type rules work, we have the current situation where the first argument is a "const char *", and the second argument _logically_ should be a pointer to such an entity, but because that would have caused bogus warnings for any code that just used a regular "char **" without any const at all, that wasn't an option.

So that explains why ANSI C has insane imbalances like this. It's easy to add a "const" to a _first-level_ pointer to say "we allow both const and regular pointers to this thing", but sadly you can't do it for a pointer to such a pointer.

			Linus
Previous: Junio C HamanoNext: Adrian Bunk
Message 10 of 12 in “diff --stat: allow custom diffstat output width.”
  1. 1/3 diff --stat: allow custom diffstat output width.Junio C Hamano, Sep 27, 2006
  2. David RientjesSep 27, 2006
  3. Linus TorvaldsSep 28, 2006
  4. Junio C HamanoSep 28, 2006
  5. Linus TorvaldsSep 28, 2006
  6. Junio C HamanoSep 29, 2006
  7. Junio C HamanoSep 29, 2006
  8. Linus TorvaldsSep 29, 2006
  9. Junio C HamanoSep 29, 2006
  10. Linus TorvaldsSep 29, 2006
  11. Adrian BunkSep 28, 2006
  12. Johannes SchindelinSep 28, 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.