libstdc++/7989: ios::showbase doesn't work when outputting 0
paolo@gcc.gnu.org
paolo@gcc.gnu.org
Thu Sep 26 13:26:00 GMT 2002
Synopsis: ios::showbase doesn't work when outputting 0
Responsible-Changed-From-To: unassigned->paolo
Responsible-Changed-By: paolo
Responsible-Changed-When: Thu Sep 26 12:44:00 2002
Responsible-Changed-Why:
Analyzed.
State-Changed-From-To: open->closed
State-Changed-By: paolo
State-Changed-When: Thu Sep 26 12:44:00 2002
State-Changed-Why:
Not a bug: gcc-2.95.2 is *incorrect*.
Indeed, for simplicity sake, compare
<C>:
#include <stdio.h>
int main()
{
printf("%#x\n", 5);
printf("%#x\n", 0);
return 0;
}
vs <C++>:
#include <iostream>
using namespace std;
int main()
{
cout.setf(ios::showbase);
cout.setf(ios::hex, ios::basefield);
cout << 5 << endl;
cout << 0 << endl;
}
Only with gcc-3.1 the output is the same for both, that is:
0x5
0
In fact, the ISO/IEC Standard 14882 for C++ prescribes (22.2.2.2.2 and table 57) that the output must be identical to that obtained with the "%#x" format for the C library
function printf().
Thanks for your report, Paolo.
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=7989
More information about the Gcc-bugs
mailing list