Announcement

Collapse
No announcement yet.

Linux 5.3 Enables "-Wimplicit-fallthrough" Compiler Flag

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Linux 5.3 Enables "-Wimplicit-fallthrough" Compiler Flag

    Phoronix: Linux 5.3 Enables "-Wimplicit-fallthrough" Compiler Flag

    The recent work on enabling "-Wimplicit-fallthrough" behavior for the Linux kernel has culminated in Linux 5.3 with actually being able to universally enable this compiler feature...

    http://www.phoronix.com/scan.php?pag...it-Fallthrough

  • #2
    Good flag, these can slip through all the time

    Comment


    • #3
      So they don't use -Wextra by default?

      Comment


      • #4
        Surprising that it took so long. This was known to be a source of bugs for decades. For example, Java also introduced a safe switch just recently.

        Comment


        • #5
          Does not the Linux kernel have any commit hook or something that gets ran that does static code analysis?

          Comment


          • #6
            The Linux kernel contains extra switch statements because it isn't written in a programming language with dynamic dispatch (runtime dispatch).

            Comment


            • #7
              Originally posted by caligula View Post
              Surprising that it took so long. This was known to be a source of bugs for decades. For example, Java also introduced a safe switch just recently.
              and with Go fallthrough is explicit, though I have not yet come across a reason to use it myself

              Comment


              • #8
                Originally posted by atomsymbol View Post
                The Linux kernel contains extra switch statements because it isn't written in a programming language with dynamic dispatch (runtime dispatch).
                Extra switch statements? Can you elaborate on why you think Java has both, the C style switches and dynamic dispatch?

                Comment


                • #9
                  Originally posted by caligula View Post
                  Extra switch statements? Can you elaborate on why you think Java has both, the C style switches and dynamic dispatch?
                  Expressing the semantics of object.method(arg) in C means to write code like:
                  • switch(object->type) { case T1: S1; case T2: S2; }
                  • if(object->type == T1) S1; else if(object->type == T2) S2;
                  • method_table[object->type](object, arg)
                  C codes contain groups of expressions/statements involving switches, ifs or method-tables that are semantically equivalent to dynamic dispatch expressions in other languages.

                  In C, the object's type may exist decoupled from the object.


                  https://en.wikipedia.org/wiki/Syntactic_sugar

                  Comment


                  • #10
                    Originally posted by atomsymbol View Post

                    Expressing the semantics of object.method(arg) in C means to write code like:
                    • switch(object->type) { case T1: S1; case T2: S2; }
                    • if(object->type == T1) S1; else if(object->type == T2) S2;
                    • method_table[object->type](object, arg)
                    [FONT=arial, helvetica, sans-serif]C codes contain groups of expressions/statements involving switches, ifs or method-tables that are semantically equivalent to dynamic dispatch expressions in other languages.
                    Cool story bro, but it doesn't work that way (two first two examples). The whole point of methods is that you can implement new cases without changing the switch logic. So it's definitely not equivalent. The main difference is the dependency inversion.

                    Comment

                    Working...
                    X