Bug in VC7.1?

  • Thread starter Thread starter Christoph Rabel
  • Start date Start date
C

Christoph Rabel

Hi!

When compiling the following program in release mode I get
as output:

22

#include <iostream>
using namespace std;

int f() {
static int i;
return ++i;
}

int main()
{
cout << f() << f() << "\n";
}


Now, while I know, that the order of evaluation is
unspecified I think that the output 22 is clearly wrong.

In my humble opinion it should be either 21 or 12.

Is this a bug?

Christoph
 
When I compile that with VC7.1, I get 21 as the output. Exactly what
command-line options are you using in your build?

-cd
 
Nevermind - I neglected to do a release build as you indicated. Yes, that's
a bug - the result should be 21 or 12 as you surmised. This bug appears to
be fixed in the current Whidbey alpha. If you're having trouble in
production work due to this bug, you should contact product support and
request a hotfix (there might be one available already).

-cd
 
Carl said:
Nevermind - I neglected to do a release build as you indicated. Yes, that's
a bug - the result should be 21 or 12 as you surmised. This bug appears to
be fixed in the current Whidbey alpha. If you're having trouble in
production work due to this bug, you should contact product support and
request a hotfix (there might be one available already).

No problem here, this code was just an example to some
students that the order of evaluation is unspecified. I was
only surprised that I get 22 and wanted a confirmation that
it is a bug.

Thx,

Christoph
 
Back
Top