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

Re: [PATCH] Trivial warning fix for imap-send.c

From
Linus Torvalds <torvalds@osdl.org>
Date
Mar 12, 2006, 16:57 UTC
Message-ID
<Pine.LNX.4.64.0603120847500.3618@g5.osdl.org>
In-Reply-To
<slrne17urp.fr9.mdw@metalzone.distorted.org.uk>
On Sun, 12 Mar 2006, Mark Wooding wrote:
Show 9 quoted lines
> "Art Haas" <ahaas@airmail.net> wrote:
> 
> > -			execl( "/bin/sh", "sh", "-c", srvc->tunnel, 0 );
> > +			execl( "/bin/sh", "sh", "-c", srvc->tunnel, NULL );
> 
> This is not the right fix.  NULL can be simply a #define for 0 (see
> 6.3.2.3#3 and 7.17).  You need to write (char *)0 or (char *)NULL.  I
> prefer to avoid the macro NULL entirely, since its misleading behaviour
> is precisely what got us into this mess.
It's perfectly fine.

Quite frankly, if you have a 64-bit C compiler that doesn't make "NULL" be "((void *)0)" (or equivalent - some compilers will actually have NULL as an intrisic, because especially if they also support C++, NULL has some really magical properties there), you should switch vendors as quickly as humanly possible.

The "#define NULL 0" practice is still _legal_ C, but that doesn't make it any less broken. It's K&R traditional, but git requires ANSI prototypes and some fancy features from modern compilers, so K&R compilers aren't welcome anyway, and if their headers don't define NULL as a void pointer, their headers are simply _broken_.

So in modern C, using NULL at the end of a varargs array as a pointer is perfectly sane, and the extra cast is just ugly and bowing to bad programming practices and makes no sense to anybody who never saw the horror that is K&R.

It's akin to trying to not using prototypes, or to trying to limit your externally visible names to 7 characters. It was "appropriate" about two decades ago, these days it's just cuddling broken setups that have been broken for a long long time.

Btw, the reason NULL _has_ to be a pointer ("((void *)0)" or otherwise) is simply that if it isn't, you not only won't get reasonable varargs behaviour, you'll also miss real warnings. I've seen broken code like

	int i = NULL;

in my life, and if the compiler doesn't warn about that, then the compiler is BROKEN, and not worth supporting as a programmer.

			Linus
Previous: Jeff KingNext: Mark Wooding
Message 9 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.