goto case null

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Clive Dixon

    #1

    goto case null

    If C# (VS 2003) allows switch on null, why does it not allow "goto case
    null":

    switch (someString)
    {
    case "BlahBlahBl ah":
    break;

    case null:
    break;

    default:
    goto case null;

    }

    Compiler error:
    "No such label 'case 0:' within the scope of the goto statement"

    Is this an omission or is there some good reason for disallowing it?

    --
    =============== =======
    Clive Dixon
    Digita Ltd. (www.digita.com)



  • SirMike

    #2
    Re: goto case null

    Dnia Thu, 2 Nov 2006 14:19:56 -0000, Clive Dixon napisa³(a):
    Compiler error:
    "No such label 'case 0:' within the scope of the goto statement"
    case 0 is not a label :)

    --
    SirMike - http://www.sirmike.org

    C makes it easy to shoot yourself in the foot; C++ makes it harder, but
    when you do, it blows away your whole leg. - Bjarne Stroustrup

    Comment

    • Clive Dixon

      #3
      Re: goto case null

      Agreed. But what I have written is "case null", not "case 0". I wouldn't
      have thought it beyond the wit of the compiler writers to make this work.

      It seems that I can work around this by writing "goto case (string)null".
      Clearly the compiler is assuming for some reason that I'm doing a switch on
      type 'int' even though it's on type 'string', and converting null to 0.
      (Though I'm not clear why it would do this. This is C#, not C++...)

      --
      =============== =======
      Clive Dixon
      Digita Ltd. (www.digita.com)


      "SirMike" <sirmike@FUCKSP AMMERSpoczta.on et.plwrote in message
      news:1rdwvu0tik 81y.1piyj4d1x3l mt$.dlg@40tude. net...
      Dnia Thu, 2 Nov 2006 14:19:56 -0000, Clive Dixon napisa³(a):
      >
      >Compiler error:
      >"No such label 'case 0:' within the scope of the goto statement"
      >
      case 0 is not a label :)
      >
      --
      SirMike - http://www.sirmike.org
      >
      C makes it easy to shoot yourself in the foot; C++ makes it harder, but
      when you do, it blows away your whole leg. - Bjarne Stroustrup

      Comment

      • Christof Nordiek

        #4
        Re: goto case null

        This is boviously a bug in the c#-compiler of VS2003. Yes, it does interpret
        'null' as zero in the 'goto case'. I tested it with an int switch
        expression.

        As i tested also, this is corrected in VS2005.

        "Clive Dixon" <clived.nolunch eonmeat@digita. noluncheonmeat. comschrieb im
        Newsbeitrag news:eo3G6no$GH A.2192@TK2MSFTN GP02.phx.gbl...
        If C# (VS 2003) allows switch on null, why does it not allow "goto case
        null":
        >
        switch (someString)
        {
        case "BlahBlahBl ah":
        break;
        >
        case null:
        break;
        >
        default:
        goto case null;
        >
        }
        >
        Compiler error:
        "No such label 'case 0:' within the scope of the goto statement"
        >
        Is this an omission or is there some good reason for disallowing it?
        >
        --
        =============== =======
        Clive Dixon
        Digita Ltd. (www.digita.com)
        >
        >
        >

        Comment

        Working...