From 3391803039365598153
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,53d56717e82ab663
X-Google-Attributes: gidf78e5,public
From: Anders Pytte <anders@milkweed.com>
Subject: Re: cout << null pointers
Date: 2000/07/08
Message-ID: <B58BAAC8.6E61%anders@milkweed.com>#1/1
X-Deja-AN: 643682295
Content-transfer-encoding: 7BIT
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
References: <39656D42.E049FCAA@ix.netcom.com>
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
Content-Type: text/plain; charset=US-ASCII
X-Complaints-To: abuse@demon.net
X-Mail2News-Path: news.demon.net!mulga.cs.mu.oz.au
X-Trace: mail2news.demon.co.uk 962999385 mail2news:18249 mail2news mail2news.demon.co.uk
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
User-Agent: Microsoft-Outlook-Express-Macintosh-Edition/5.02.2022
MIME-version: 1.0
NNTP-posting-date: Fri, 07 Jul 2000 15:40:47 EDT
Newsgroups: comp.std.c++

in article 39656D42.E049FCAA@ix.netcom.com, Paul Meyerholtz at
pholtz@ix.netcom.com wrote on 7/8/00 5:08 AM:

> I have found an inconsistent output by various compilers of the following:
> 
> char * p = 0;
> cout * q = "";
> 
> cout << p << "\n\n";
> cout << q;
> 
> Most compilers seem to handle "cout << q" without a problem.  (But I
> have heard that Visual C++ 6 fails this test).
> 
> However, the handling of "cout << p" seems to cause problems for most
> computers, with results from segment faults to garbage output.
> (CodeWarrior for the Mac, which I use, outputs a couple of garbage
> characters, but always the same ones).
> 
> Why is the output of p and q different?

In the above, "cout << p" says, print the c string stored at address 0,
while "cout << q" says, print a c string of zero length. Why should these
produce the same output?

> Is there anything in the standard about this?  Should cout check for the
> null pointer? 

Perhaps, but that is not how it is defined. Actually, I'm not aware of any
standard functions that take char* as an input and that check for null. This
appears to be the responsibility of the caller :-)

Anders.

-- 
Anders Pytte                                   Milkweed Software
PO Box 32                                  voice: (802) 586-2545
Craftsbury, VT 05826                  email: anders@milkweed.com

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]




