public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/16396] New: cout of volatile char * prints funny
@ 2004-07-06 23:25 ramsdell at mitre dot org
  2004-07-07  0:08 ` [Bug libstdc++/16396] ostream << volatile char* converts to ostream << bool bangerth at dealii dot org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: ramsdell at mitre dot org @ 2004-07-06 23:25 UTC (permalink / raw)
  To: gcc-bugs

Are volatile C strings printed in C++ by special rules?  I get 1 no matter
what is in the string.  See the comments at the end of the following C++ program.
                                                                                
$ cat vcp.cc
#include <cstdio>
#include <iostream>
 
int main(int argc, char **argv)
{
  volatile char str[] = { 'a', 'b', '\0' };
  std::printf("%s\n", str);
  std::cout << str << "\n";
  return 0;
}
 
/*
 * $ uname -a
 * Linux localhost.localdomain 2.6.5-1.358 #1 Sat May 8 09:04:50 EDT 2004 i686
i686 i386 GNU/Linux
 * $ gcc --version
 * gcc (GCC) 3.3.3 20040412 (Red Hat Linux 3.3.3-7)
 * Copyright (C) 2003 Free Software Foundation, Inc.
 * This is free software; see the source for copying conditions.  There is NO
 * warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * $ make vcp
 * g++     vcp.cc   -o vcp
 * $ ./vcp
 * ab
 * 1
 * $
 */
$

-- 
           Summary: cout of volatile char * prints funny
           Product: gcc
           Version: 3.3.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ramsdell at mitre dot org
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i386-redhat-linux
  GCC host triplet: i386-redhat-linux
GCC target triplet: i386-redhat-linux


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


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

* [Bug libstdc++/16396] ostream << volatile char*  converts to  ostream << bool
  2004-07-06 23:25 [Bug c++/16396] New: cout of volatile char * prints funny ramsdell at mitre dot org
@ 2004-07-07  0:08 ` bangerth at dealii dot org
  2004-07-08 14:48 ` pcarlini at suse dot de
  2004-08-23  0:05 ` pcarlini at suse dot de
  2 siblings, 0 replies; 4+ messages in thread
From: bangerth at dealii dot org @ 2004-07-07  0:08 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bangerth at dealii dot org  2004-07-07 00:08 -------
The argument to operator<< is of type 'volatile char*', which
is converted to bool in absence of a better match. Since the
pointer is non-null, the bool is 'true', which is printed as '1'.

Now, whether this conversion is correct, I don't know -- a matter
for the libstdc++ people. 

W.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c++                         |libstdc++
            Summary|cout of volatile char *     |ostream << volatile char*
                   |prints funny                |converts to  ostream << bool


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


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

* [Bug libstdc++/16396] ostream << volatile char*  converts to  ostream << bool
  2004-07-06 23:25 [Bug c++/16396] New: cout of volatile char * prints funny ramsdell at mitre dot org
  2004-07-07  0:08 ` [Bug libstdc++/16396] ostream << volatile char* converts to ostream << bool bangerth at dealii dot org
@ 2004-07-08 14:48 ` pcarlini at suse dot de
  2004-08-23  0:05 ` pcarlini at suse dot de
  2 siblings, 0 replies; 4+ messages in thread
From: pcarlini at suse dot de @ 2004-07-08 14:48 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pcarlini at suse dot de  2004-07-08 14:48 -------
Gaby, could you please have a look at this PR? I believe we can close it as 
not a bug (FWIW, Icc8.0 also converts to bool and outputs 1), but would
appreciate if you could explain in simple, yet technically sound, terms, why
among all the operator<< that we implement (27.6.2.1) operator<<(bool) is
the right one for a volatile char* type. Thanks in advance. 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |gdr at gcc dot gnu dot org
                   |dot org                     |
             Status|UNCONFIRMED                 |ASSIGNED


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


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

* [Bug libstdc++/16396] ostream << volatile char*  converts to  ostream << bool
  2004-07-06 23:25 [Bug c++/16396] New: cout of volatile char * prints funny ramsdell at mitre dot org
  2004-07-07  0:08 ` [Bug libstdc++/16396] ostream << volatile char* converts to ostream << bool bangerth at dealii dot org
  2004-07-08 14:48 ` pcarlini at suse dot de
@ 2004-08-23  0:05 ` pcarlini at suse dot de
  2 siblings, 0 replies; 4+ messages in thread
From: pcarlini at suse dot de @ 2004-08-23  0:05 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pcarlini at suse dot de  2004-08-23 00:05 -------
The explanation is actually rather straightforward: roughly, missing a perfect
match, a match with minor adjustments and a match with promotion, a match with
standard conversions is looked for: there is a standard conversion from pointer
to bool, *not* to other integral types.

For more details, see Vendevoorde/Josuttis appendix B and the standard, sec 4.

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


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


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

end of thread, other threads:[~2004-08-23  0:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-07-06 23:25 [Bug c++/16396] New: cout of volatile char * prints funny ramsdell at mitre dot org
2004-07-07  0:08 ` [Bug libstdc++/16396] ostream << volatile char* converts to ostream << bool bangerth at dealii dot org
2004-07-08 14:48 ` pcarlini at suse dot de
2004-08-23  0:05 ` pcarlini at suse dot de

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