Function call, postfix inc and exception behavior

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Goran Sliskovic

    Function call, postfix inc and exception behavior

    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


  • Victor Bazarov

    #2
    Re: Function call, postfix inc and exception behavior

    "Goran Sliskovic" <gsliskov@yahoo .com> wrote...[color=blue]
    > 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[/color]
    this[color=blue]
    > was defined behaviour as i++ should be evaluated prior to function call[/color]
    and[color=blue]
    > have all side-effects completed. Am I missing something (exception thrown
    > makes this undefined?) or is it a bug in the compiler?[/color]

    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


    Comment

    • Goran Sliskovic

      #3
      Re: Function call, postfix inc and exception behavior


      "Victor Bazarov" <v.Abazarov@com Acast.net> wrote in message
      news:nRrpc.5447 1$iF6.4920610@a ttbi_s02...[color=blue]
      > "Goran Sliskovic" <gsliskov@yahoo .com> wrote...[color=green]
      > > I have following piece of code:
      > >
      > > #include <iostream>
      > > using namespace std;
      > >
      > > void f(int i) {
      > > throw (int)0;
      > > }[/color][/color]
      ....[color=blue][color=green]
      > > Using VC7.1 I get 1 as a result in debug mode, 0 in release. I thought[/color]
      > this[color=green]
      > > was defined behaviour as i++ should be evaluated prior to function call[/color]
      > and[color=green]
      > > have all side-effects completed. Am I missing something (exception[/color][/color]
      thrown[color=blue][color=green]
      > > makes this undefined?) or is it a bug in the compiler?[/color]
      >
      > 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
      >[/color]

      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


      Comment

      Working...