By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,192 Members | 856 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,192 IT Pros & Developers. It's quick & easy.

Function call, postfix inc and exception behavior

P: n/a
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
Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Goran Sliskovic" <gs******@yahoo.com> wrote...
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
Jul 22 '05 #2

P: n/a

"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:nRrpc.54471$iF6.4920610@attbi_s02...
"Goran Sliskovic" <gs******@yahoo.com> wrote...
I have following piece of code:

#include <iostream>
using namespace std;

void f(int i) {
throw (int)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


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
Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.