Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Brite
  • 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 (Darkly)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Uncategorized
  3. today i learned that if you don't end a C file with a newline, the compiler is free to steal your apes

today i learned that if you don't end a C file with a newline, the compiler is free to steal your apes

Scheduled Pinned Locked Moved Uncategorized
15 Posts 11 Posters 0 Views
  • 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.
  • Andy WingoW Andy Wingo

    today i learned that if you don't end a C file with a newline, the compiler is free to steal your apes

    Furbland's Very Cool Mastodon™G This user is from outside of this forum
    Furbland's Very Cool Mastodon™G This user is from outside of this forum
    Furbland's Very Cool Mastodon™
    wrote last edited by
    #3

    @wingo all my apes, gone

    1 Reply Last reply
    0
    • ✧✦Catherine✦✧W ✧✦Catherine✦✧

      @wingo it's really funny isn't it

      Andy WingoW This user is from outside of this forum
      Andy WingoW This user is from outside of this forum
      Andy Wingo
      wrote last edited by
      #4

      @whitequark very serious language

      Stefan EissingI 1 Reply Last reply
      0
      • Andy WingoW Andy Wingo

        today i learned that if you don't end a C file with a newline, the compiler is free to steal your apes

        Alexander MonakovA This user is from outside of this forum
        Alexander MonakovA This user is from outside of this forum
        Alexander Monakov
        wrote last edited by
        #5

        @wingo UB for compile-time (not run-time) conditions is bonkers (there are more like this).

        Josh SimmonsD 1 Reply Last reply
        0
        • Andy WingoW Andy Wingo

          today i learned that if you don't end a C file with a newline, the compiler is free to steal your apes

          Daphne ‘FOSDEM’-KendalD This user is from outside of this forum
          Daphne ‘FOSDEM’-KendalD This user is from outside of this forum
          Daphne ‘FOSDEM’-Kendal
          wrote last edited by
          #6

          @wingo Submitting a patch to gcc that auto-enables -Ofast if there’s no newline at the end of the file

          1 Reply Last reply
          0
          • Andy WingoW Andy Wingo

            @whitequark very serious language

            Stefan EissingI This user is from outside of this forum
            Stefan EissingI This user is from outside of this forum
            Stefan Eissing
            wrote last edited by
            #7

            @wingo @whitequark 😌Ritchie probably spins in his grave.

            These standardization foobars commonly happen when implementors with commercial interests seek to „compromize“ out of being buggy.

            Update: @david_chisnall points to this probably just being a misbehaviour of earlier tool chains. See below.

            David Chisnall (*Now with 50% more sarcasm!*)D 1 Reply Last reply
            0
            • Andy WingoW Andy Wingo

              today i learned that if you don't end a C file with a newline, the compiler is free to steal your apes

              doragasuD This user is from outside of this forum
              doragasuD This user is from outside of this forum
              doragasu
              wrote last edited by
              #8

              @wingo I remember some C compilers throwing warnings if you did not end the file with a newline, when I worked with TI DSPs more than a decade ago, so I tend to end all my C/H files with a newline since then. Didn't know this is officially a cause for undefined behavior 🤦‍♂️

              1 Reply Last reply
              0
              • Alexander MonakovA Alexander Monakov

                @wingo UB for compile-time (not run-time) conditions is bonkers (there are more like this).

                Josh SimmonsD This user is from outside of this forum
                Josh SimmonsD This user is from outside of this forum
                Josh Simmons
                wrote last edited by
                #9

                @amonakov @wingo does anyone know which compiler couldn't handle eof as a line ending marker? I assume there must have been some implementation that caused it to be designated as UB?

                Andy WingoW David Chisnall (*Now with 50% more sarcasm!*)D 2 Replies Last reply
                0
                • Josh SimmonsD Josh Simmons

                  @amonakov @wingo does anyone know which compiler couldn't handle eof as a line ending marker? I assume there must have been some implementation that caused it to be designated as UB?

                  Andy WingoW This user is from outside of this forum
                  Andy WingoW This user is from outside of this forum
                  Andy Wingo
                  wrote last edited by
                  #10

                  @dotstdy @amonakov i had just assumed that it was the famous bundler and transpiler, `cat`

                  1 Reply Last reply
                  0
                  • Andy WingoW Andy Wingo

                    today i learned that if you don't end a C file with a newline, the compiler is free to steal your apes

                    tessaraktT This user is from outside of this forum
                    tessaraktT This user is from outside of this forum
                    tessarakt
                    wrote last edited by
                    #11

                    @wingo No diagnostic required?

                    Arne MertzA 1 Reply Last reply
                    0
                    • Stefan EissingI Stefan Eissing

                      @wingo @whitequark 😌Ritchie probably spins in his grave.

                      These standardization foobars commonly happen when implementors with commercial interests seek to „compromize“ out of being buggy.

                      Update: @david_chisnall points to this probably just being a misbehaviour of earlier tool chains. See below.

                      David Chisnall (*Now with 50% more sarcasm!*)D This user is from outside of this forum
                      David Chisnall (*Now with 50% more sarcasm!*)D This user is from outside of this forum
                      David Chisnall (*Now with 50% more sarcasm!*)
                      wrote last edited by
                      #12

                      @icing @wingo @whitequark

                      This has nothing to do with commercial vendors. The original Lex / YACC could not handle token streams that did not terminate with a separator. The very first C compiler would not correctly handle files that did not end with a newline (or, I think, other whitespace) and so the UNIX convention was to always end a file with a newline.

                      This limitation was picked up by most early C compilers, because they used the same tooling.

                      Modern compilers tend not to use this kind of tooling (and newer versions can handle this corner case), but the standard didn't want to exclude them.

                      As a QoI issue, most compilers will simply diagnose this and interpret the file as if it had a newline at the end. Early compilers would, as I recall, simply stop in the middle of parsing (I think. A parser generator I used 20+ years ago had this issue, but I don't remember the details).

                      Stefan EissingI 1 Reply Last reply
                      0
                      • Josh SimmonsD Josh Simmons

                        @amonakov @wingo does anyone know which compiler couldn't handle eof as a line ending marker? I assume there must have been some implementation that caused it to be designated as UB?

                        David Chisnall (*Now with 50% more sarcasm!*)D This user is from outside of this forum
                        David Chisnall (*Now with 50% more sarcasm!*)D This user is from outside of this forum
                        David Chisnall (*Now with 50% more sarcasm!*)
                        wrote last edited by
                        #13

                        @dotstdy @amonakov @wingo

                        Yes, the original AT&C C compiler.

                        1 Reply Last reply
                        0
                        • David Chisnall (*Now with 50% more sarcasm!*)D David Chisnall (*Now with 50% more sarcasm!*)

                          @icing @wingo @whitequark

                          This has nothing to do with commercial vendors. The original Lex / YACC could not handle token streams that did not terminate with a separator. The very first C compiler would not correctly handle files that did not end with a newline (or, I think, other whitespace) and so the UNIX convention was to always end a file with a newline.

                          This limitation was picked up by most early C compilers, because they used the same tooling.

                          Modern compilers tend not to use this kind of tooling (and newer versions can handle this corner case), but the standard didn't want to exclude them.

                          As a QoI issue, most compilers will simply diagnose this and interpret the file as if it had a newline at the end. Early compilers would, as I recall, simply stop in the middle of parsing (I think. A parser generator I used 20+ years ago had this issue, but I don't remember the details).

                          Stefan EissingI This user is from outside of this forum
                          Stefan EissingI This user is from outside of this forum
                          Stefan Eissing
                          wrote last edited by
                          #14

                          @david_chisnall @wingo @whitequark Thanks for the insight.

                          1 Reply Last reply
                          0
                          • tessaraktT tessarakt

                            @wingo No diagnostic required?

                            Arne MertzA This user is from outside of this forum
                            Arne MertzA This user is from outside of this forum
                            Arne Mertz
                            wrote last edited by
                            #15

                            @tessarakt @wingo nothing required at all. Undefined behavior means compilers can do as they wish. Fail with diagnostic, fail silently, do what you expect them to do, or something else entirely.

                            1 Reply Last reply
                            0
                            • R ActivityRelay shared this topic
                            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.
                            Powered by NodeBB Contributors
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups