why the VC8 treat goto and switch-case different?

Discussion in 'C++' started by miaohua1982@gmail.com, Nov 27, 2006.

  1. Guest

    under the same warning level, the code is:

    class X{
    public:
    X(){}
    virtual void g(){}
    };
    void f(int i){
    if(i<10)
    goto jump1;
    X x1;
    jump1: //warning C4533: initialization of 'x1' is skipped by 'goto
    jump1',why there is only a warning?

    switch(i){
    case 1:
    X x2;
    break;
    case 2: //error C2360: initialization of 'x2' is skipped by 'case'
    label
    X x3;
    break;
    }
    }
    , Nov 27, 2006
    #1
    1. Advertising

  2. Bo Persson Guest

    wrote:
    > under the same warning level, the code is:
    >
    > class X{
    > public:
    > X(){}
    > virtual void g(){}
    > };
    > void f(int i){
    > if(i<10)
    > goto jump1;
    > X x1;
    > jump1: //warning C4533: initialization of 'x1' is skipped by
    > 'goto jump1',why there is only a warning?
    >
    > switch(i){
    > case 1:
    > X x2;
    > break;
    > case 2: //error C2360: initialization of 'x2' is skipped by
    > 'case' label
    > X x3;
    > break;
    > }
    > }


    The language standard doesn't say anything about different levels, it just
    speaks of a 'diagnostic' required for certain faults. The rest is up to the
    implementation, inluding any additional messages for these kinds of
    constructs.

    Most compilers have a setting like 'treat warnings as errors', to get away
    with your problem.


    Bo Persson
    Bo Persson, Nov 27, 2006
    #2
    1. Advertising

  3. Guest

    Thank you very much!

    "Bo Persson дµÀ£º
    "
    > wrote:
    > > under the same warning level, the code is:
    > >
    > > class X{
    > > public:
    > > X(){}
    > > virtual void g(){}
    > > };
    > > void f(int i){
    > > if(i<10)
    > > goto jump1;
    > > X x1;
    > > jump1: //warning C4533: initialization of 'x1' is skipped by
    > > 'goto jump1',why there is only a warning?
    > >
    > > switch(i){
    > > case 1:
    > > X x2;
    > > break;
    > > case 2: //error C2360: initialization of 'x2' is skipped by
    > > 'case' label
    > > X x3;
    > > break;
    > > }
    > > }

    >
    > The language standard doesn't say anything about different levels, it just
    > speaks of a 'diagnostic' required for certain faults. The rest is up to the
    > implementation, inluding any additional messages for these kinds of
    > constructs.
    >
    > Most compilers have a setting like 'treat warnings as errors', to get away
    > with your problem.
    >
    >
    > Bo Persson
    , Nov 28, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Xamle Eng

    Why treat text nodes as nodes?

    Xamle Eng, May 13, 2005, in forum: XML
    Replies:
    8
    Views:
    491
    Fredrik Lundh
    May 28, 2005
  2. Gabriel B.
    Replies:
    0
    Views:
    366
    Gabriel B.
    Feb 13, 2005
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,804
    Smokey Grindel
    Dec 2, 2006
  4. Replies:
    9
    Views:
    303
    Michal Kleczek
    May 27, 2013
  5. Replies:
    31
    Views:
    218
    Tim Rentsch
    Apr 15, 2014
Loading...

Share This Page