public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/60959] New: Does “cout<<(char*)NULL” doing “close(1)” ?
@ 2014-04-25  2:44 sree.gooogle at gmail dot com
  2014-04-25  3:00 ` [Bug c++/60959] " sree.gooogle at gmail dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: sree.gooogle at gmail dot com @ 2014-04-25  2:44 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60959

            Bug ID: 60959
           Summary: Does “cout<<(char*)NULL” doing “close(1)” ?
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sree.gooogle at gmail dot com

In the following piece of C++ code I have used cout<<(char*)NULL; after this
line, my program printing nothing to the output screen. Does it mean I have
done close(1) with cout here?

#include<iostream>
using namespace std;

void f(){
    cout<<"\nfun\n";
}

main(){
cout<<(char*)NULL;
f(); //not getting printed !
cout<<"\nhello\n";  //not getting printed !
cout<<"hii how are you?"; //not getting printed, why??
}

compiled using:
g++ myprog.cpp
run:
./a.out

o/p:
 Prints nothing

I have tried this code in gcc as well as DevCpp compiler, same behavior
observed. Is this a compiler bug? Please provide detailed information about
this behavior. 

Thank you!
>From gcc-bugs-return-449838-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Fri Apr 25 02:51:27 2014
Return-Path: <gcc-bugs-return-449838-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 31660 invoked by alias); 25 Apr 2014 02:51:27 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 31627 invoked by uid 48); 25 Apr 2014 02:51:22 -0000
From: "pinskia at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/60959]=?UTF-8?Q? Does “cout?=<<(char*)=?UTF-8?Q?NULL” doing “close?=(1)=?UTF-8?Q?” ?=?
Date: Fri, 25 Apr 2014 02:51:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: c++
X-Bugzilla-Version: unknown
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: pinskia at gcc dot gnu.org
X-Bugzilla-Status: RESOLVED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: bug_status resolution
Message-ID: <bug-60959-4-zR7eUVXskC@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-60959-4@http.gcc.gnu.org/bugzilla/>
References: <bug-60959-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2014-04/txt/msg01858.txt.bz2
Content-length: 555

http://gcc.gnu.org/bugzilla/show_bug.cgi?id`959

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
No it sets the badbit on the stream which causes nothing to be printed after
that.

      if (!__s)
 __out.setstate(ios_base::badbit);


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/60959] Does “cout<<(char*)NULL” doing “close(1)” ?
  2014-04-25  2:44 [Bug c++/60959] New: Does “cout<<(char*)NULL” doing “close(1)” ? sree.gooogle at gmail dot com
@ 2014-04-25  3:00 ` sree.gooogle at gmail dot com
  2014-04-25  3:05 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: sree.gooogle at gmail dot com @ 2014-04-25  3:00 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60959

--- Comment #2 from Sreenath U S <sree.gooogle at gmail dot com> ---
"sets the badbit on the stream which causes nothing to be printed after that.";
So this is a defined behavior or it varies on compiler to compiler?


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/60959] Does “cout<<(char*)NULL” doing “close(1)” ?
  2014-04-25  2:44 [Bug c++/60959] New: Does “cout<<(char*)NULL” doing “close(1)” ? sree.gooogle at gmail dot com
  2014-04-25  3:00 ` [Bug c++/60959] " sree.gooogle at gmail dot com
@ 2014-04-25  3:05 ` pinskia at gcc dot gnu.org
  2014-04-25  3:50 ` sree.gooogle at gmail dot com
  2014-04-25 10:03 ` redi at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2014-04-25  3:05 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60959

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Sreenath U S from comment #2)
> "sets the badbit on the stream which causes nothing to be printed after
> that."; So this is a defined behavior or it varies on compiler to compiler?

I think it is undefined behavior, GCC decides to play it safe.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/60959] Does “cout<<(char*)NULL” doing “close(1)” ?
  2014-04-25  2:44 [Bug c++/60959] New: Does “cout<<(char*)NULL” doing “close(1)” ? sree.gooogle at gmail dot com
  2014-04-25  3:00 ` [Bug c++/60959] " sree.gooogle at gmail dot com
  2014-04-25  3:05 ` pinskia at gcc dot gnu.org
@ 2014-04-25  3:50 ` sree.gooogle at gmail dot com
  2014-04-25 10:03 ` redi at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: sree.gooogle at gmail dot com @ 2014-04-25  3:50 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60959

--- Comment #4 from Sreenath U S <sree.gooogle at gmail dot com> ---
Okay Thanks. One more thing, Is there any way to make the remaining cout
statements to get printed in gcc without removing the faulty
cout<<(char*)NULL;?


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/60959] Does “cout<<(char*)NULL” doing “close(1)” ?
  2014-04-25  2:44 [Bug c++/60959] New: Does “cout<<(char*)NULL” doing “close(1)” ? sree.gooogle at gmail dot com
                   ` (2 preceding siblings ...)
  2014-04-25  3:50 ` sree.gooogle at gmail dot com
@ 2014-04-25 10:03 ` redi at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2014-04-25 10:03 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60959

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Andrew is correct, the standard says:

   Requires: s shall not be a null pointer.

So your program has undefined behaviour and should be fixed.

You can clear the badbit with cout.clear()


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-04-25 10:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-25  2:44 [Bug c++/60959] New: Does “cout<<(char*)NULL” doing “close(1)” ? sree.gooogle at gmail dot com
2014-04-25  3:00 ` [Bug c++/60959] " sree.gooogle at gmail dot com
2014-04-25  3:05 ` pinskia at gcc dot gnu.org
2014-04-25  3:50 ` sree.gooogle at gmail dot com
2014-04-25 10:03 ` redi at gcc dot gnu.org

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).