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

Re: [PATCH] Use explicit pointers for execl...() sentinels.

From
Jeff King <peff@peff.net>
Date
Mar 13, 2006, 03:31 UTC
Message-ID
<20060313033121.GA14601@coredump.intra.peff.net>
In-Reply-To
<20060312200812.3fb04638.tihirvon@gmail.com>
On Sun, Mar 12, 2006 at 08:08:12PM +0200, Timo Hirvonen wrote:
> NULL pointer does not point to any data, it just says it's 'empty'.  So
> it doesn't need to be same type pointer as specified in the function
> prototype.  Pointers are just addresses, it doesn't matter from to code
> generation point of view whether it is (char *)0 or (void *)0.

Sorry, but I think you're wrong according to the C standard. Pointers of different types do NOT have to share the same representation (e.g., there have been some platforms where char* and int* were different sizes). A void pointer must be capable of representing any type of pointer (for example, holding the largest possible type). However, if sizeof(void *) == 8 and sizeof(char *) == 4, you have a problem with variadic functions which are expecting to pull 4 byte off the stack.

In a non-variadic function, the compiler would do the right implicit casting. In a variadic function, it can't.

The real question is, does git want to care about portability to such platforms.

If you remain unconvinced, I can try to find chapter and verse of the standard.

> sizeof(unsigned long) is sizeof(void *) in real world.

Are you saying that because it encompasses all of the platforms you've worked on, or do you have some evidence that it is largely the case? It certainly isn't guaranteed by the C standard.

> > Because, according to the C and POSIX specs, they're not wrong.
> They didn't think of 64-bit architectures back then, I suppose.

No, they did think of those issues; they intentionally left such sizing up to the implementation to allow C to grow with the hardware. Mostly you don't have to care, but as I said, typing with variadic functions is a pain.

-Peff
Previous: Timo HirvonenNext: Linus Torvalds
Message 8 of 20 in “Trivial warning fix for imap-send.c”
  1. Trivial warning fix for imap-send.cArt Haas, Mar 11, 2006
  2. Mark WoodingMar 12, 2006
  3. Junio C HamanoMar 12, 2006
  4. Use explicit pointers for execl...() sentinels.Mark Wooding, Mar 12, 2006
  5. Timo HirvonenMar 12, 2006
  6. Mark WoodingMar 12, 2006
  7. Timo HirvonenMar 12, 2006
  8. Jeff KingMar 13, 2006
  9. Linus TorvaldsMar 12, 2006
  10. Mark WoodingMar 12, 2006
  11. A Large Angry SCMMar 12, 2006
  12. H. Peter AnvinMar 13, 2006
  13. A Large Angry SCMMar 13, 2006
  14. Linus TorvaldsMar 13, 2006
  15. H. Peter AnvinMar 13, 2006
  16. Linus TorvaldsMar 13, 2006
  17. Olivier GalibertMar 13, 2006
  18. Jeff KingMar 13, 2006
  19. H. Peter AnvinMar 13, 2006
  20. Linus TorvaldsMar 12, 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.