Function call, postfix inc and exception behavior

G

Goran Sliskovic

Hi,
I have following piece of code:

#include <iostream>
using namespace std;

void f(int i) {
throw (int)0;
}

int main()
{
int i = 0;
try {
f(i++);
}
catch(int x) {
}
cout << i << endl;
return 0;
}

Using VC7.1 I get 1 as a result in debug mode, 0 in release. I thought this
was defined behaviour as i++ should be evaluated prior to function call and
have all side-effects completed. Am I missing something (exception thrown
makes this undefined?) or is it a bug in the compiler?

Regards,
Goran
 
V

Victor Bazarov

Goran Sliskovic said:
I have following piece of code:

#include <iostream>
using namespace std;

void f(int i) {
throw (int)0;
}

int main()
{
int i = 0;
try {
f(i++);
}
catch(int x) {
}
cout << i << endl;
return 0;
}

Using VC7.1 I get 1 as a result in debug mode, 0 in release. I thought this
was defined behaviour as i++ should be evaluated prior to function call and
have all side-effects completed. Am I missing something (exception thrown
makes this undefined?) or is it a bug in the compiler?

Looks like a bug. Probably an optimization issue, since you get
different behaviour in Debug and Release mode.

I've added m.p.vc.lang to the list of newsgroups, perhaps somebody
at MSoft will see it.

Victor
 
G

Goran Sliskovic

Victor Bazarov said:
Looks like a bug. Probably an optimization issue, since you get
different behaviour in Debug and Release mode.

I've added m.p.vc.lang to the list of newsgroups, perhaps somebody
at MSoft will see it.

Victor

Thnx, I have found out it is a bug, and also already known one. So I guess
my understanding of standard was ok.

Regards,
Goran
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top