1. 37
  1. 19

    It seems that when you linked to the Stack Overflow question, the title got transmogrified to

    What is the “–>” operator in C++?

    The two hyphens were replaced with an en dash to result in something even more nonsensical than the original code ;-)

    1. 4

      The easiest way to see that someone is using Apple products is that their operating system breaks anything code-related like that, by replacing -- with —, replacing "" with ”“, etc.

      Luckily, you can disable that (look for “smart punctuation”), but it seems pretty arrogant for Apple to assume that nobody cares about what character their key presses actually results in. Two dashes and an en-dash carry completely different meaning.

      1. 3

        The people who do care about -- are much more likely to know how to write -- than the people who want an are able to write an without the -- shortcut.

        From that perspective, this is a sensible default.

        1. 2

          But the consequences of automatically replacing characters like that are much bigger than the consequences of not doing it. There are so many pages on the web with shell commands which don’t work because Apple’s software automatically broke them.

          1. 1

            What software from Apple are you referring to?

            My blog posts use a filter that converts straight quotes to curly quotes, and two dashes to one m-dash, but it of course does not affect content within code blocks. But I create all content in a Linux VPS.

            1. 1

              Both iOS and macOS will automatically convert ascii quotes to unicode “smart quotes” and two dashes to unicode en-dashes (or em-dashes, I don’t know) in all native text fields. That means, when you use Safari on a Mac to write a blog post, the system will mess up your content even before your CMS’s backend even sees the text.

              1. 3

                This is something that, at least on iOS, is hidden behind a Smart punctuation setting that must be opt-in—I don’t remember turning it off, and I’ve just enabled it to test it. It doesn’t ring a bell on macOS, but it might be possible.

                (Later edit: Huh, seems that macOS Safari has its own text substitutions which are not synced to the OS-level settings, so it does seem that by default it substitutes smart quotes and dashes for their plain counterparts when typing)

                Otherwise, the bulk of the problem is smart punctuation plugins in CMSes, when they’re not context-aware. Just yesterday I opened up an O’Reilly book on sed and awk and it had all its snippets in smart quotes…

                1. 2

                  Thanks for the clarification, I was not aware of this behavior!

          2. 2

            I wouldn’t put all of the blame on Apple—blogs and CMSes do this kind of thing too. One giveaway is when someone follows a digit with a double quote, like

            Now the screen should say, "The number you entered was 5".

            and the closing quote is (incorrectly) turned into a double-prime (″). The Apple OSes don’t do this, and yet it’s rampant across the web. You see it everywhere once you start looking for it.

        2. 9

          First time c code has made me laugh out loud. I needed that today.

          There are wonderful “answers” in the rest of the SO thread, I liked this one illustrating how you can change the speed of the decrement.

          int x = 10;
          while( 0 <---- x )
             printf("%d ", x);
          1. 2

            Won’t that fall afoul of the single-modification rule? After all, the result of

            x += ++x;

            is famously undefined because x is modified twice without a sequence point in between. I’d also have to look up if --x is even an lvalue in C. It is in C++ I believe, but this is the sort of weird edge case where the two languages might actually disagree. (I believe the UB/sequence point issue applies to both.)

            1. 3

              I don’t think --x is an lvalue. It is equivalent to x-=1, which is equivalent to x=x-1 except that the lvalue x is evaluated only once. An assignment expression has the value of the left operand after the assignment, but is not an lvalue.

          2. 9

            Everyone forgets the sprong and tadpole operators.

            1. 3

              The arrow operator illusion does not work in ancient versions of C? Did C have significant whitespace?

              1. 4

                It seems like C has had significant whitespace, yes.

                For the article, I have searched a lot to find out when this changed, but I was unable to find it. Because of your comment, I continued my search.

                I’ve found an online version of the C89 standard, and in, I found this:

                1. White-space characters separating tokens are no longer significant. Preprocessing tokens are converted into tokens. The resulting tokens are syntactically and semantically analyzed and translated.

                This means that this comment has been in the C standard for over 30 years! And it still says no longer.

                1. 14

                  Section 2.1.1 is describing the eight translation phases. (A compiler is not actually required to make eight separate passes, but it does need to work the same as if it did.) What is saying that white space stops being significant at the seventh phase.

                  1. 11

                    Oh god, that changes everything.

                  2. 1

                    Additionally, see The New C Standard: An Economic and Cultural Commentary, page 137:

                    White-space characters separating tokens are no longer significant

                    White-space is not part of the syntax of the C language. It is only significant in separating characters in the lexical grammar and in some contexts in the preprocessor. This statement could have equally occurred in translation phase 5

                    So I think it’s highly unlikely whitespace was ever meaningful to C.

                2. 3

                  this part in the standard was directly taken from the C99 standard, so it is not that new. Sadly, older standards are no longer available on the internet.

                  I think you meant C89 here? Because I found a copy of that quite easily which contains a similar statement: “7. White-space characters separating tokens are no longer significant. Preprocessing tokens are converted into tokens.

                  Also, I think C89 was the first C standard? Before that whatever was in K&R book was the “standard”.

                  1. 3

                    Hi! Yes, I found it as well after the question by qznc. Not being able to find it while writing my article is sad, but it is even worse that I’ve used this version of the C89 standard before.

                    Also, you are right about C89 being the first standard indeed. However, between C89 and C99, there have been two more versions.

                  2. 3

                    It’s not symmetrical, because 0<--x is different from x-->0.

                    1. 2

                      I’m not sure the answer to pedantry is more pedantry, but symmetry doesn’t mean identity.

                      y=x^2 is symmetrical about the y axis in the cartesian plane. But -4 doesn’t equal 4.

                      But more generally, even if “technically correct” (and I could be wrong!), I’m not sure my comment (or yours?) adds to the conversation. I’ll try and restrain myself in future.

                      1. 2

                        It’s the internet, where correct and incorrect are much more than two letters apart. Here we go,

                        I usually use the following definition of symmetry, from Wikipedia.

                        In physics, a symmetry of a physical system is a physical or mathematical feature of the system (observed or intrinsic) that is preserved or remains unchanged under some transformation.

                        I agree with you. This is a bit narrow definition.

                    2. 3

                      This works in Java as well. I had a bad habit of using it in the Neo4j code base for a long time, thinking I was super clever. Someone eventually had enough of those antics and got rid of most of them, but you can still find a few loops like this in the code, albeit nowadays split up into while a-- > 0, like https://github.com/neo4j/neo4j/blob/4.2/community/record-storage-engine/src/main/java/org/neo4j/internal/recordstorage/PhysicalLogCommandReaderV3_0_10.java#L582

                      It’s really a horrible thing to do, actively hostile to whoever is reading it since it’s not at all obvious what’s happening.

                      1. 2

                        In the early days of SO, I once stumbled upon a user who was, essentially. a troll. But a very creative and imaginative one. He asked questions exactly like these, in a very innocent tone, and effectively got answerers to wander down some deep rabbit holes for quite a while until they realize they’d been had. Whoever this was, he was a master of the game. And eventually banned from SO, I’m pretty sure. I wish I would have bookmarked some of those.