Bug in VC7.1?

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
 
C

Carl Daniel [VC++ MVP]

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
 
C

Carl Daniel [VC++ MVP]

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
 
C

Christoph Rabel

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top