public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Joe Buck <jbuck@synopsys.com>
To: Olivier.Galibert@mines.u-nancy.fr (Olivier Galibert)
Cc: egcs@cygnus.com
Subject: Re: linux libio status
Date: Wed, 15 Oct 1997 11:12:00 -0000	[thread overview]
Message-ID: <199710151604.JAA22390@atrus.synopsys.com> (raw)
In-Reply-To: <19971015095211.03621@renaissance.loria.fr>

> 
> On Tue, Oct 14, 1997 at 11:23:49PM -0700, Joe Buck wrote:
> > We need to silence these warnings.  For the NULL, I suggest a global
> > s/NULL/0/ in the C++ iostreams headers.  There is no reason to write
> > NULL, it is just a source of problems like this (*especially* since
> > we have changed C++ to be strict about void*).
> 
> Don't use '0' but '0L'. This way you will be OK with NULL in stdargs
> when int=32b and pointer=64b.

And you'll be broken on platforms where sizeof(long) != sizeof(pointer),
or at least you would if it weren't for the fact that C++ requires
prototypes for all functions.  Remember, we are talking about C++ here,
not C.

Stroustrup says (The C++ Programming Language, 3rd Edition, p. 88)
"Because of C++'s tighter type checking, the use of plain 0, rather than
any suggested NULL macro, leads to fewer problems.  If you feel that you
must define NULL, use

const int NULL = 0;

..."

There is a similar discussion in the comp.lang.c++ FAQ.

In C++, there are always prototypes.  Thus 0 or 0L makes no difference,
and in fact the "standard null pointer" is essentially 0 in C++.  The
argument is coerced to the proper pointer.  However, standard C++ does
not let you convert (void *) to (T *) without a cast, so defining NULL
as (void *)0 is completely broken in C++.  It used to work in g++, but
that was an extension (furthermore this extension prevented g++ from
implementing the standard overloading rules correctly).  Hence

The only exception is functions with ... in their spec.  Here, neither 0
nor 0L will result in portable code.  Your suggestion switches the
erroneous assumption that sizeof(T *) == sizeof(int) with another
erroneous assumption, that sizeof(T *) == sizeof(long).  Worse, you leave
users with the idea that they can safely use NULL for any null pointer
type, even in variadic functions.  Sorry, you can't do that in standard
C++.  For variadic functions, users must declare any optional arguments
correctly, period.

Conclusion: we should deprecate the use of NULL in C++ code.  If we
must define NULL for C++ code, it must be 0.  Nothing else.




  parent reply	other threads:[~1997-10-15 11:12 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-10-14 23:23 Joe Buck
1997-10-15  0:06 ` Richard Henderson
1997-10-15  0:52 ` Olivier Galibert
1997-10-15  8:25   ` [ECGS] " chip
1997-10-15 11:12   ` Joe Buck [this message]
1997-10-15 12:10     ` Olivier Galibert
1997-10-15 16:51       ` [ECGS] " chip
1997-10-15 20:16       ` Joe Buck
1997-10-15 20:16         ` Olivier Galibert
1997-10-16 12:53           ` Pal Engstad
1997-10-15 11:12   ` Peter Seebach
1997-10-15 20:16     ` Joe Buck
     [not found]   ` <199710151419.JAA20162.cygnus.egcs@monolith.solon.com>
1997-10-15 16:51     ` Jason Merrill
1997-10-15 20:16       ` Peter Seebach
1997-10-15 22:29         ` Jason Merrill
1997-10-16  8:31           ` Peter Seebach
1997-10-16 15:19             ` Jason Merrill
1997-10-16 12:53               ` Peter Seebach
1997-10-16 15:19       ` Paul Koning
     [not found] <199710150623.XAA06491.cygnus.egcs@atrus.synopsys.com>
1997-10-15  2:10 ` Jason Merrill
1997-10-15  9:15   ` Joe Buck
1997-10-15 11:12     ` Per Bothner
1997-10-15 14:33       ` Joe Buck
1997-10-15 16:51         ` Per Bothner
     [not found]         ` <199710152351.QAA02138.cygnus.egcs@cygnus.com>
1997-10-16  1:51           ` Jason Merrill
1997-10-16 12:58             ` Alexandre Oliva
1997-10-16 12:58             ` Joe Buck
1997-10-17 12:53               ` Jason Merrill
1997-10-15 16:51       ` Peter Seebach
1997-10-15 14:33     ` Richard Henderson
1997-10-15 12:10 Greg Galloway
1997-10-15 20:16 ` Joe Buck
1997-10-16 12:58 ` H.J. Lu
1997-10-15 12:10 Greg Galloway
1997-10-16 12:53 ` H.J. Lu

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=199710151604.JAA22390@atrus.synopsys.com \
    --to=jbuck@synopsys.com \
    --cc=Olivier.Galibert@mines.u-nancy.fr \
    --cc=egcs@cygnus.com \
    /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 read-only IMAP folder(s) and NNTP newsgroup(s).