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. General Programming
  3. C#
  4. Unreachable code detected?

Unreachable code detected?

Scheduled Pinned Locked Moved C#
comtoolsquestion
13 Posts 9 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.
  • J Jasmine2501

    When the compiler gives this warning, does the code actually compile? Is any MSIL generated for the code that is unreachable?

    "Quality Software since 1983!"
    http://www.smoothjazzy.com/ - see the "Programming" section for freeware tools and articles.

    G Offline
    G Offline
    Gareth H
    wrote on last edited by
    #3

    Jasmine2501, Try it out and see what happens, but why would you want something like this to be compiled? If you have code that is unreachable you might as well just hit the delete key on it. Regards, Gareth.

    J 1 Reply Last reply
    0
    • G Gareth H

      Jasmine2501, Try it out and see what happens, but why would you want something like this to be compiled? If you have code that is unreachable you might as well just hit the delete key on it. Regards, Gareth.

      J Offline
      J Offline
      Jasmine2501
      wrote on last edited by
      #4

      Yes exactly, but I'm interested in proving that it results in no-codez - because I'm hitting the delete key on someone else's stuff and they swear the compiler warning is just something to be ignored.

      "Quality Software since 1983!"
      http://www.smoothjazzy.com/ - see the "Programming" section for freeware tools and articles.

      P L 2 Replies Last reply
      0
      • J Jasmine2501

        Yes exactly, but I'm interested in proving that it results in no-codez - because I'm hitting the delete key on someone else's stuff and they swear the compiler warning is just something to be ignored.

        "Quality Software since 1983!"
        http://www.smoothjazzy.com/ - see the "Programming" section for freeware tools and articles.

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

        I believe it can be ignored as much as it warns you for unassigned variables etc, but if you want to modify someone else's code, how about commenting out segments you wish to change, or better yet just clone the project and play with it to your heart's content.

        He who makes a beast out of himself gets rid of the pain of being a man

        J 1 Reply Last reply
        0
        • J Jasmine2501

          When the compiler gives this warning, does the code actually compile? Is any MSIL generated for the code that is unreachable?

          "Quality Software since 1983!"
          http://www.smoothjazzy.com/ - see the "Programming" section for freeware tools and articles.

          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #6

          Yes and no. A switch statement with a return immediately before a break. The break is unreachable so is not compiled into IL.

          Deja View - the feeling that you've seen this post before.

          My blog | My articles

          L 1 Reply Last reply
          0
          • J Jasmine2501

            Yes exactly, but I'm interested in proving that it results in no-codez - because I'm hitting the delete key on someone else's stuff and they swear the compiler warning is just something to be ignored.

            "Quality Software since 1983!"
            http://www.smoothjazzy.com/ - see the "Programming" section for freeware tools and articles.

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #7

            Hi, I use #if false and #endif for hiding code. :)

            Luc Pattyn [Forum Guidelines] [My Articles]


            This month's tips: - before you ask a question here, search CodeProject, then Google; - the quality and detail of your question reflects on the effectiveness of the help you are likely to get; - use PRE tags to preserve formatting when showing multi-line code snippets.


            1 Reply Last reply
            0
            • J Jasmine2501

              When the compiler gives this warning, does the code actually compile? Is any MSIL generated for the code that is unreachable?

              "Quality Software since 1983!"
              http://www.smoothjazzy.com/ - see the "Programming" section for freeware tools and articles.

              R Offline
              R Offline
              Rob Philpott
              wrote on last edited by
              #8

              No, there isn't - which I'm a bit surprised about. Makes no sense to include unreachable code I guess. Confirmed via Reflector/ildasm.

              Regards, Rob Philpott.

              1 Reply Last reply
              0
              • P phannon86

                I believe it can be ignored as much as it warns you for unassigned variables etc, but if you want to modify someone else's code, how about commenting out segments you wish to change, or better yet just clone the project and play with it to your heart's content.

                He who makes a beast out of himself gets rid of the pain of being a man

                J Offline
                J Offline
                Jasmine2501
                wrote on last edited by
                #9

                Well I'm working in a company environment... anything I do has to integrate with everything else. This is a super-large project. It takes Visual Studio literally 5 minutes to compile the site and all the DLLs and everything. I'm optimizing things, and I do have free reign on the code at the moment, but I do have to justify what I do sometimes. I realize that the warnings don't prevent the thing from working, but they are not be ignored. One of my mentors always said "warnings are like a sign saying the bridge is out - it won't keep you from going down the road, but there's gonna be trouble eventually"

                "Quality Software since 1983!"
                http://www.smoothjazzy.com/ - see the "Programming" section for freeware tools and articles.

                1 Reply Last reply
                0
                • J Jasmine2501

                  When the compiler gives this warning, does the code actually compile? Is any MSIL generated for the code that is unreachable?

                  "Quality Software since 1983!"
                  http://www.smoothjazzy.com/ - see the "Programming" section for freeware tools and articles.

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

                  Just be sure it's not the result of conditional compilation. Though even then it should be written so as not to produce a warning.

                  J 1 Reply Last reply
                  0
                  • P Pete OHanlon

                    Yes and no. A switch statement with a return immediately before a break. The break is unreachable so is not compiled into IL.

                    Deja View - the feeling that you've seen this post before.

                    My blog | My articles

                    L Offline
                    L Offline
                    Luc Pattyn
                    wrote on last edited by
                    #11

                    :cool:

                    Luc Pattyn [Forum Guidelines] [My Articles]


                    This month's tips: - before you ask a question here, search CodeProject, then Google; - the quality and detail of your question reflects on the effectiveness of the help you are likely to get; - use PRE tags to preserve formatting when showing multi-line code snippets.


                    1 Reply Last reply
                    0
                    • P PIEBALDconsult

                      Just be sure it's not the result of conditional compilation. Though even then it should be written so as not to produce a warning.

                      J Offline
                      J Offline
                      Jasmine2501
                      wrote on last edited by
                      #12

                      Yes, our site originally had over 100 compiler warnings when you build. I consider that a Bad Thing. I've got it down to 23 at the moment, but I want to get it down to zero. Warnings are the computer telling you that something stupid is going on, not a broken something stupid, but still something stupid, and in most cases you just delete the thing, or code it a different way and it's functionally equivalent, but doesn't cause the warning. The break after a return statement is a good example... not having the break eliminates the warning, the break isn't necessary, and it's probably just there because somebody was told to put breaks in their switch/case blocks and was never told what it actually does.

                      "Quality Software since 1983!"
                      http://www.smoothjazzy.com/ - see the "Programming" section for freeware tools and articles.

                      1 Reply Last reply
                      0
                      • C carbon_golem

                        Use ILDasm on your assembly to find out. Very nifty tool. Scott

                        "Run for your life from any man who tells you that money is evil. That sentence is the leper's bell of an approaching looter." --Ayn Rand

                        P Offline
                        P Offline
                        Paul Conrad
                        wrote on last edited by
                        #13

                        carbon_golem wrote:

                        Use ILDasm on your assembly to find out. Very nifty tool.

                        I second that.

                        "I guess it's what separates the professionals from the drag and drop, girly wirly, namby pamby, wishy washy, can't code for crap types." - Pete O'Hanlon

                        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