Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. Head, meet desk

Head, meet desk

Scheduled Pinned Locked Moved The Weird and The Wonderful
csharpquestion
3 Posts 3 Posters 5 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Richard DeemingR Offline
    Richard DeemingR Offline
    Richard Deeming
    wrote on last edited by
    #1

    What idiot wrote goto case default instead of goto default in one of my C# switch statements, causing an infinite loop? :doh: It certainly couldn't have been me. :-O For future reference: given:

    enum Foo { One, Two }

    then:

    switch (foo)
    {
    case Foo.One: goto default;
    default: Console.WriteLine("Default");
    }

    compiles to:

    if (foo != 0) { }
    Console.WriteLine("Default");

    whereas:

    switch (foo)
    {
    case Foo.One: goto case default;
    default: Console.WriteLine("Default");
    }

    compiles to:

    if (foo == Foo.One)
    {
    while (true)
    {
    }
    }
    Console.WriteLine("Default");


    "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

    "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

    Greg UtasG Z 2 Replies Last reply
    0
    • Richard DeemingR Richard Deeming

      What idiot wrote goto case default instead of goto default in one of my C# switch statements, causing an infinite loop? :doh: It certainly couldn't have been me. :-O For future reference: given:

      enum Foo { One, Two }

      then:

      switch (foo)
      {
      case Foo.One: goto default;
      default: Console.WriteLine("Default");
      }

      compiles to:

      if (foo != 0) { }
      Console.WriteLine("Default");

      whereas:

      switch (foo)
      {
      case Foo.One: goto case default;
      default: Console.WriteLine("Default");
      }

      compiles to:

      if (foo == Foo.One)
      {
      while (true)
      {
      }
      }
      Console.WriteLine("Default");


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      Greg UtasG Offline
      Greg UtasG Offline
      Greg Utas
      wrote on last edited by
      #2

      JRST @.

      <p><a href="https://github.com/GregUtas/robust-services-core/blob/master/README.md">Robust Services Core</a>
      <em>The fox knows many things, but the hedgehog knows one big thing.</em></p>

      1 Reply Last reply
      0
      • Richard DeemingR Richard Deeming

        What idiot wrote goto case default instead of goto default in one of my C# switch statements, causing an infinite loop? :doh: It certainly couldn't have been me. :-O For future reference: given:

        enum Foo { One, Two }

        then:

        switch (foo)
        {
        case Foo.One: goto default;
        default: Console.WriteLine("Default");
        }

        compiles to:

        if (foo != 0) { }
        Console.WriteLine("Default");

        whereas:

        switch (foo)
        {
        case Foo.One: goto case default;
        default: Console.WriteLine("Default");
        }

        compiles to:

        if (foo == Foo.One)
        {
        while (true)
        {
        }
        }
        Console.WriteLine("Default");


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        Z Offline
        Z Offline
        ZurdoDev
        wrote on last edited by
        #3

        A good reason not to use goto. ;)

        Social Media - A platform that makes it easier for the crazies to find each other. Everyone is born right handed. Only the strongest overcome it. Fight for left-handed rights and hand equality.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups