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. Unreachable code detected

Unreachable code detected

Scheduled Pinned Locked Moved The Weird and The Wonderful
comfunctionaltutorialquestionlearning
12 Posts 7 Posters 0 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.
  • P PIEBALDconsult

    Well, you wouldn't want it to fall through, would you?

    M Offline
    M Offline
    Marc Clifton
    wrote on last edited by
    #3

    Well, on a X86, you'd need at 3 bit errors on the instruction to convert a RET (0xC2) to a NOP (0x90), but hey, I'm all for defensive programming! Marc

    Imperative to Functional Programming Succinctly Higher Order Programming

    1 Reply Last reply
    0
    • M Marc Clifton

      So, I just compiled a small web service that I, of course, did not write. Got almost 100 "Unreachable code detected" errors. Why? Here's an example:

      case [some case]:
      return CallSomeFunction(xmldata);
      break;

      :rolleyes: Marc

      Imperative to Functional Programming Succinctly Higher Order Programming

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #4

      It is a correct message :confused: The compiler should not "guess" that the break is redundant; it should give a warning for the programmer to ignore.

      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

      P 1 Reply Last reply
      0
      • L Lost User

        It is a correct message :confused: The compiler should not "guess" that the break is redundant; it should give a warning for the programmer to ignore.

        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #5

        # pragma warning disable

        1 Reply Last reply
        0
        • M Marc Clifton

          So, I just compiled a small web service that I, of course, did not write. Got almost 100 "Unreachable code detected" errors. Why? Here's an example:

          case [some case]:
          return CallSomeFunction(xmldata);
          break;

          :rolleyes: Marc

          Imperative to Functional Programming Succinctly Higher Order Programming

          L Offline
          L Offline
          ledtech3
          wrote on last edited by
          #6

          Well there is the problem, The last line says "Break" so it did ;)

          1 Reply Last reply
          0
          • M Marc Clifton

            So, I just compiled a small web service that I, of course, did not write. Got almost 100 "Unreachable code detected" errors. Why? Here's an example:

            case [some case]:
            return CallSomeFunction(xmldata);
            break;

            :rolleyes: Marc

            Imperative to Functional Programming Succinctly Higher Order Programming

            T Offline
            T Offline
            TheGreatAndPowerfulOz
            wrote on last edited by
            #7

            wouldn't those be warnings? are is "warnings as errors" turned on?

            If your actions inspire others to dream more, learn more, do more and become more, you are a leader.-John Q. Adams
            You must accept one of two basic premises: Either we are alone in the universe, or we are not alone in the universe. And either way, the implications are staggering.-Wernher von Braun
            Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.-Albert Einstein

            M 1 Reply Last reply
            0
            • T TheGreatAndPowerfulOz

              wouldn't those be warnings? are is "warnings as errors" turned on?

              If your actions inspire others to dream more, learn more, do more and become more, you are a leader.-John Q. Adams
              You must accept one of two basic premises: Either we are alone in the universe, or we are not alone in the universe. And either way, the implications are staggering.-Wernher von Braun
              Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.-Albert Einstein

              M Offline
              M Offline
              Marc Clifton
              wrote on last edited by
              #8

              TheGreatAndPowerfulOz wrote:

              wouldn't those be warnings? are is "warnings as errors" turned on?

              They are warnings. I hate warnings. Warnings should be fixed, even if their not treated as errors by the IDE. Marc

              Imperative to Functional Programming Succinctly Higher Order Programming

              T R 2 Replies Last reply
              0
              • M Marc Clifton

                TheGreatAndPowerfulOz wrote:

                wouldn't those be warnings? are is "warnings as errors" turned on?

                They are warnings. I hate warnings. Warnings should be fixed, even if their not treated as errors by the IDE. Marc

                Imperative to Functional Programming Succinctly Higher Order Programming

                T Offline
                T Offline
                TheGreatAndPowerfulOz
                wrote on last edited by
                #9

                agreed

                If your actions inspire others to dream more, learn more, do more and become more, you are a leader.-John Q. Adams
                You must accept one of two basic premises: Either we are alone in the universe, or we are not alone in the universe. And either way, the implications are staggering.-Wernher von Braun
                Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.-Albert Einstein

                1 Reply Last reply
                0
                • M Marc Clifton

                  So, I just compiled a small web service that I, of course, did not write. Got almost 100 "Unreachable code detected" errors. Why? Here's an example:

                  case [some case]:
                  return CallSomeFunction(xmldata);
                  break;

                  :rolleyes: Marc

                  Imperative to Functional Programming Succinctly Higher Order Programming

                  G Offline
                  G Offline
                  Gary R Wheeler
                  wrote on last edited by
                  #10

                  When I started programming, structured programming was all the rage, and one of its fundamental principles was "single entry, single exit" for every block of code. While structured programming in no longer a primary development paradigm, it's principles are still valid. Putting a return inside a case is the Devil's work.

                  Software Zen: delete this;

                  R 1 Reply Last reply
                  0
                  • M Marc Clifton

                    TheGreatAndPowerfulOz wrote:

                    wouldn't those be warnings? are is "warnings as errors" turned on?

                    They are warnings. I hate warnings. Warnings should be fixed, even if their not treated as errors by the IDE. Marc

                    Imperative to Functional Programming Succinctly Higher Order Programming

                    R Offline
                    R Offline
                    Rob Grainger
                    wrote on last edited by
                    #11

                    Amen to that, I use code analysis tools to and eliminate all the issues those detect. Occassionally I have to use a pragma/code comment when I really intentionally did something, but its rare, and worth it for the number of bugs I detect early.

                    "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

                    1 Reply Last reply
                    0
                    • G Gary R Wheeler

                      When I started programming, structured programming was all the rage, and one of its fundamental principles was "single entry, single exit" for every block of code. While structured programming in no longer a primary development paradigm, it's principles are still valid. Putting a return inside a case is the Devil's work.

                      Software Zen: delete this;

                      R Offline
                      R Offline
                      Rob Grainger
                      wrote on last edited by
                      #12

                      I fundamentally disagree, but it does depend on the language. In C++ and many other languages I use RAII instead to ensure nothing is ever missed.

                      "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

                      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