git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@osdl.org>
To: Mark Wooding <mdw@distorted.org.uk>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] Trivial warning fix for imap-send.c
Date: Sun, 12 Mar 2006 08:57:02 -0800 (PST)	[thread overview]
Message-ID: <Pine.LNX.4.64.0603120847500.3618@g5.osdl.org> (raw)
In-Reply-To: <slrne17urp.fr9.mdw@metalzone.distorted.org.uk>



On Sun, 12 Mar 2006, Mark Wooding wrote:
> "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

  parent reply	other threads:[~2006-03-12 16:57 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-03-11 19:29 [PATCH] Trivial warning fix for imap-send.c Art Haas
2006-03-12 10:44 ` Mark Wooding
2006-03-12 11:27   ` Junio C Hamano
2006-03-12 13:59     ` [PATCH] Use explicit pointers for execl...() sentinels Mark Wooding
2006-03-12 15:13       ` Timo Hirvonen
2006-03-12 17:32         ` Mark Wooding
2006-03-12 18:08           ` Timo Hirvonen
2006-03-13  3:31             ` Jeff King
2006-03-13  4:12               ` Horst von Brand
2006-03-14  0:42                 ` [OT] " Jeff King
2006-03-12 16:57   ` Linus Torvalds [this message]
2006-03-12 18:01     ` [PATCH] Trivial warning fix for imap-send.c Mark Wooding
2006-03-12 19:20       ` A Large Angry SCM
2006-03-13  2:59         ` H. Peter Anvin
2006-03-13  4:36           ` A Large Angry SCM
2006-03-13  5:22             ` Linus Torvalds
2006-03-13  6:37               ` H. Peter Anvin
2006-03-13  6:46                 ` Linus Torvalds
2006-03-13 16:37                 ` Olivier Galibert
2006-03-13  3:38         ` Jeff King
2006-03-13  4:14           ` Horst von Brand
2006-03-13 16:26             ` Linus Torvalds
2006-03-13  6:41           ` H. Peter Anvin
2006-03-12 21:51       ` Horst von Brand
2006-03-12 23:02       ` Linus Torvalds

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.64.0603120847500.3618@g5.osdl.org \
    --to=torvalds@osdl.org \
    --cc=git@vger.kernel.org \
    --cc=mdw@distorted.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).