This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c++/1520: cout prints in the wrong order.
- To: gcc-gnats at gcc dot gnu dot org
- Subject: c++/1520: cout prints in the wrong order.
- From: magnus at gol dot com
- Date: 28 Dec 2000 03:26:15 -0000
- Reply-To: magnus at gol dot com
>Number: 1520
>Category: c++
>Synopsis: cout prints in the wrong order.
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: unassigned
>State: open
>Class: wrong-code
>Submitter-Id: net
>Arrival-Date: Wed Dec 27 19:36:00 PST 2000
>Closed-Date:
>Last-Modified:
>Originator: Magnus Back
>Release: 2.96
>Organization:
>Environment:
Reading specs from /usr/lib/gcc-lib/i586-mandrake-linux/2.96/specs
gcc version 2.96 20000731 (Linux-Mandrake 7.2)
>Description:
The printout order is different between optimized and unoptimized code.
The optimized code seems correct.
(My code is "wrong")
[root@back 21dayscpp]# g++ -Wall hello.cxx -ohello2
[root@back 21dayscpp]# ./hello2
Hello World!
12 : 35Test
Enter value 1
6
Enter value 2
7
second: 6
first: 6
[root@back 21dayscpp]# g++ -Wall -O hello.cxx -ohello2
[root@back 21dayscpp]# ./hello2
Hello World!
12 : 35Test
Enter value 1
6
Enter value 2
7
first: second: 6
6
>How-To-Repeat:
This produces incorrect code:
g++ -Wall hello.cxx -ohello
This produces correct code:
g++ -Wall -O hello.cxx -ohello
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="fault.txt"
Content-Disposition: inline; filename="fault.txt"
------------------------ test.h ------------------------------------
#include <iostream>
typedef unsigned short int USHORT;
typedef unsigned long int ULONG;
inline unsigned short int examine(USHORT first = 1, int second = 2);
float examine(ULONG first = 1, int second = 2);
unsigned short int examine(USHORT first, int second)
{
if (first < second)
second = first;
else
first = second;
cout << "second: "<< second << "\n";
return first;
}
float examine(ULONG first, int second)
{
if (static_cast<USHORT>(first) < second)
second = first;
else
first = second;
cout << "second: "<< second << "\n";
return first;
}
------------------------ hello.cxx ------------------------------------
#include <iostream>
#include "test.h"
int main()
{
USHORT inOne;
int inTwo;
cout << "Hello World!\n";
int x = 5;
int y = 7;
cout << "\n";
cout << x+y << " : " << x*y << "Test";
cout << "\n";
cout << "Enter value 1\n";
cin >> inOne;
cout << "Enter value 2\n";
cin >> inTwo;
cout << "first: " << examine(inOne,inTwo) << "\n";
return 0;
}