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. The Lounge
  3. Visual Basic 6 did this, why can't you, C#?

Visual Basic 6 did this, why can't you, C#?

Scheduled Pinned Locked Moved The Lounge
csharpc++helpquestion
27 Posts 17 Posters 50 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.
  • O obermd

    I blame Ken Thompson for the vast majority of bugs in today's software. The entire concept of null terminated strings and buffers is simply asking for trouble. DEC and IBM both had descriptor-based buffers, which gives the OS calls that manipulate buffers a way to block buffer overflows.

    E Offline
    E Offline
    englebart
    wrote on last edited by
    #21

    C was just an easier, portable assembly language. I blame the overflow buffer errors on the chip designers that encouraged storing local variables on the call stack! Call stack pointer should be read only except for jsr and ret instructions.

    1 Reply Last reply
    0
    • Richard DeemingR Richard Deeming

      Probably because it was modelled on languages which do allow execution to fall-through, and without an explicit break / return, early adopters might have thought the C# code was falling through. [Proposal] Case fall through should be allowed · dotnet/csharplang · Discussion #603 · GitHub[^] See also Eric Lippert's comments on SO:

      Eric Lippert wrote:[^]:

      C# enforces the no-fall-through rule in every switch section, including the last one. This is so that switch sections can be re-ordered arbitrarily, possibly by mechanical tools, without introducing semantic changes in the program. C# enforces the no-fall-through rule by requiring that the end point of every switch section be unreachable. It is not necessary for a switch section to end in a break. It can end in a break, return, goto, continue, throw, or a detectable infinite loop:


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

      M Offline
      M Offline
      Mark Starr
      wrote on last edited by
      #22

      :) As opposed to an undetectable infinite loop?

      Time is the differentiation of eternity devised by man to measure the passage of human events. - Manly P. Hall Mark Just another cog in the wheel

      Richard DeemingR K 2 Replies Last reply
      0
      • M Mark Starr

        :) As opposed to an undetectable infinite loop?

        Time is the differentiation of eternity devised by man to measure the passage of human events. - Manly P. Hall Mark Just another cog in the wheel

        Richard DeemingR Offline
        Richard DeemingR Offline
        Richard Deeming
        wrote on last edited by
        #23

        Indeed. The compiler isn't magic, and there are constructs which are obvious infinite loops to a human which the compiler cannot detect as such. For example:

        switch (x)
        {
        case 1:
        while (x < 42);
        case 2:
        return 123;
        }

        Whilst we can clearly see that the loop is infinite, since x starts as 1 and is never modified within the loop, the compiler still complains:

        Quote:

        CS0163 Control cannot fall through from one case label ('case 1:') to another


        "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

        1 Reply Last reply
        0
        • M Mark Starr

          :) As opposed to an undetectable infinite loop?

          Time is the differentiation of eternity devised by man to measure the passage of human events. - Manly P. Hall Mark Just another cog in the wheel

          K Offline
          K Offline
          kalberts
          wrote on last edited by
          #24

          In my student days, "correctness proofs" were the rage. Everyone were convinced that soon, a program would be able to prove (or disprove) that a program behaved according to specifications. The first real proof we learned in that course was not a program, but a logical proof that no program analyzer can, in the general case, detect every possible infinte loop. I did understand the proof then; I don't remember the details today, and even if I found the text, I would probably be unable to explain it to someone unfamiliar with it. But I know the proof exists (just like I know that there exists a proof that you cannot trisect an arbitrary angle); I trust the experts that the proof still holds.

          1 Reply Last reply
          0
          • realJSOPR realJSOP

            You only need braces in the case when you're creating a new variable in the case. Otherwise, they're unnecessary.

            ".45 ACP - because shooting twice is just silly" - JSOP, 2010
            -----
            You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
            -----
            When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013

            K Offline
            K Offline
            kalberts
            wrote on last edited by
            #25

            They are "unnecessary" only if you accept indents and undents with no supporting braces. Braces and indents are the 2-factor element of program layout. You can equally well say that 2-factor authentication is "unneccessary" when you have already supplied a password. Some of us nevertheless think 2-factor is a good idea, both in authentication and in code layout.

            1 Reply Last reply
            0
            • D den2k88

              Small rant about dumb choices. So C# doesn't allow cascading through switch cases. Ok, understandable. So why the :elephant: does it need me to repeat the :elephant:ing break; after each and any case? There is no :elephant:ing need for it because there is nothing to break, apart from my patience. Rant over.

              GCS/GE d--(d) s-/+ a C+++ U+++ P-- L+@ E-- W+++ N+ o+ K- w+++ O? M-- V? PS+ PE Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++*      Weapons extension: ma- k++ F+2 X The shortest horror story: On Error Resume Next

              S Offline
              S Offline
              Stacy Dudovitz
              wrote on last edited by
              #26

              Allowing fall through code was/is a huge source of bugs, and does not fall in line with best practices. During any refactoring, it's not uncommon to move/reorder code. Without close scrutiny, a break in logic flow would be so easily introduced by missing the fall through code. Worse, refactoring/reordering code might be necessary, but now fallthrough code has introduced an artificial constraint. For case statements with few case points, this requirement is a minor inconvenience at best. If, however, you have numerous case points, this might be indicative of a code smell. Such code is both difficult to understand and to follow. Perhaps a different approach might be more appropriate... finite state machines, keyword/lambda method dictionaries, etc. Something to consider when designing well crafted code that adheres to best practices.

              1 Reply Last reply
              0
              • D den2k88

                Small rant about dumb choices. So C# doesn't allow cascading through switch cases. Ok, understandable. So why the :elephant: does it need me to repeat the :elephant:ing break; after each and any case? There is no :elephant:ing need for it because there is nothing to break, apart from my patience. Rant over.

                GCS/GE d--(d) s-/+ a C+++ U+++ P-- L+@ E-- W+++ N+ o+ K- w+++ O? M-- V? PS+ PE Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++*      Weapons extension: ma- k++ F+2 X The shortest horror story: On Error Resume Next

                V Offline
                V Offline
                vKaras
                wrote on last edited by
                #27

                well.. you could also use `return`, `throw` or `goto case 3` instead of `break`. I guess they didn't want to define a default behaviour witch needed to be remembered and thought of by of everyone, when writing a switch case.

                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