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 / C++ / MFC
  4. Syntax Error NOT!

Syntax Error NOT!

Scheduled Pinned Locked Moved C / C++ / MFC
linuxhelp
9 Posts 3 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 Offline
    J Offline
    jerry0davis
    wrote on last edited by
    #1

    I'm half asleep today. I ended up writing the following code.... printf("rta %s %s\n", "router""jmd", token); Even the linux gnu c compiler compiles it OK! :mad::confused:


    I feel like I'm diagonally parked in a parallel universe Jerry Davis http://www.astad.org
    http://www.jvf.co.uk

    D T 2 Replies Last reply
    0
    • J jerry0davis

      I'm half asleep today. I ended up writing the following code.... printf("rta %s %s\n", "router""jmd", token); Even the linux gnu c compiler compiles it OK! :mad::confused:


      I feel like I'm diagonally parked in a parallel universe Jerry Davis http://www.astad.org
      http://www.jvf.co.uk

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Jeremy Davis wrote: Even the linux gnu c compiler compiles it OK! I'm with the compiler. I see nothing wrong with the statement. What do you think is wrong?


      "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

      J 1 Reply Last reply
      0
      • J jerry0davis

        I'm half asleep today. I ended up writing the following code.... printf("rta %s %s\n", "router""jmd", token); Even the linux gnu c compiler compiles it OK! :mad::confused:


        I feel like I'm diagonally parked in a parallel universe Jerry Davis http://www.astad.org
        http://www.jvf.co.uk

        T Offline
        T Offline
        Tim Smith
        wrote on last edited by
        #3

        Perfectly valid code. Tim Smith I'm going to patent thought. I have yet to see any prior art.

        1 Reply Last reply
        0
        • D David Crow

          Jeremy Davis wrote: Even the linux gnu c compiler compiles it OK! I'm with the compiler. I see nothing wrong with the statement. What do you think is wrong?


          "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

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

          It's the "string1""string2" bit. It becomes "string1string2". I just never realised you could add strings like that. My bad then!


          I feel like I'm diagonally parked in a parallel universe Jerry Davis http://www.astad.org
          http://www.jvf.co.uk

          D 1 Reply Last reply
          0
          • J jerry0davis

            It's the "string1""string2" bit. It becomes "string1string2". I just never realised you could add strings like that. My bad then!


            I feel like I'm diagonally parked in a parallel universe Jerry Davis http://www.astad.org
            http://www.jvf.co.uk

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            There's really nothing special about it. String constants occupy a spot in memory, and two, contiguous, quoted strings will be right next to each other. Consider the following:

            char *pszName = "A really long string here" \
            "...and the rest of it here.";

            results in pszName pointing to "A really long string here...and the rest of it here." in memory. Make sense?


            "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

            T 1 Reply Last reply
            0
            • D David Crow

              There's really nothing special about it. String constants occupy a spot in memory, and two, contiguous, quoted strings will be right next to each other. Consider the following:

              char *pszName = "A really long string here" \
              "...and the rest of it here.";

              results in pszName pointing to "A really long string here...and the rest of it here." in memory. Make sense?


              "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

              T Offline
              T Offline
              Tim Smith
              wrote on last edited by
              #6

              That isn't how it works. The standard specifically says that the strings will be concatenated. If what you said was true, the strings would have a '\0' between them. Also, there is nothing that says that strings are placed in the EXE in the same order they are found in the source files. Tim Smith I'm going to patent thought. I have yet to see any prior art.

              D 1 Reply Last reply
              0
              • T Tim Smith

                That isn't how it works. The standard specifically says that the strings will be concatenated. If what you said was true, the strings would have a '\0' between them. Also, there is nothing that says that strings are placed in the EXE in the same order they are found in the source files. Tim Smith I'm going to patent thought. I have yet to see any prior art.

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #7

                Tim Smith wrote: The standard specifically says that the strings will be concatenated. They're not concatenated as there is nothing to concatenate. Concatenation implies two or more strings, whereas the snippet I showed only has one string. The fact that it breaks two lines, or has multiple sets of quotes, is irrelevant. Tim Smith wrote: If what you said was true, the strings would have a '\0' between them. I don't know where you pulled this from. :confused: Tim Smith wrote: Also, there is nothing that says that strings are placed in the EXE in the same order they are found in the source files. Uh, actually there is. While the preprocessor sees two separately quoted strings, once the extra quotes (and backslash) are removed, the compiler sees only one. Therefore, they are in memory in exactly the same way had they been written as one continuous string.


                "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

                T 1 Reply Last reply
                0
                • D David Crow

                  Tim Smith wrote: The standard specifically says that the strings will be concatenated. They're not concatenated as there is nothing to concatenate. Concatenation implies two or more strings, whereas the snippet I showed only has one string. The fact that it breaks two lines, or has multiple sets of quotes, is irrelevant. Tim Smith wrote: If what you said was true, the strings would have a '\0' between them. I don't know where you pulled this from. :confused: Tim Smith wrote: Also, there is nothing that says that strings are placed in the EXE in the same order they are found in the source files. Uh, actually there is. While the preprocessor sees two separately quoted strings, once the extra quotes (and backslash) are removed, the compiler sees only one. Therefore, they are in memory in exactly the same way had they been written as one continuous string.


                  "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

                  T Offline
                  T Offline
                  Tim Smith
                  wrote on last edited by
                  #8

                  Read the C++ standard section 2.13.4.3. It specifically states that: In translation phase 6 (2.1), adjacent narrow string literals are concatenated and adjacent wide string literals are concatenated. If a narrow string literal token is adjacent to a wide string literal token, the behavior is undefined... The two strings are concatentated. They way you describe it is totally wrong. It doesn't just ignore the two quotes as also covered in 2.13.4.3. It doesn't just place the two strings after each other in the EXE. Literal string pooling requires that strings be moved around. But that is probably implementation specific but that does not mean it breaks the standard. Please find the section in the standard that says it must do this. Also, a backslash is not required. Tim Smith I'm going to patent thought. I have yet to see any prior art.

                  D 1 Reply Last reply
                  0
                  • T Tim Smith

                    Read the C++ standard section 2.13.4.3. It specifically states that: In translation phase 6 (2.1), adjacent narrow string literals are concatenated and adjacent wide string literals are concatenated. If a narrow string literal token is adjacent to a wide string literal token, the behavior is undefined... The two strings are concatentated. They way you describe it is totally wrong. It doesn't just ignore the two quotes as also covered in 2.13.4.3. It doesn't just place the two strings after each other in the EXE. Literal string pooling requires that strings be moved around. But that is probably implementation specific but that does not mean it breaks the standard. Please find the section in the standard that says it must do this. Also, a backslash is not required. Tim Smith I'm going to patent thought. I have yet to see any prior art.

                    D Offline
                    D Offline
                    David Crow
                    wrote on last edited by
                    #9

                    Tim Smith wrote: Read the C++ standard section 2.13.4.3. Then I must also consider these examples that accompany the Concatenation section: Another way to continue a string is to have two or more consecutive strings. Adjacent string literals will be concatenated to produce a single string. The following example demonstrates this: "hello " "there" // is equivalent to "hello there" "hello" "there" // is equivalent to "hellothere" char *third = "Hello " "there"; // stored as "Hello there\0" Characters in concatenated strings remain distinct. For example, the strings "\xab" and "3" are concatenated to form "\xab3", rather than the single hex character \xab3. I believe this site also has a mention of how concatenation is implemented. Tim Smith wrote: In translation phase 6 (2.1), adjacent narrow string literals are concatenated and adjacent wide string literals are concatenated. If a narrow string literal token is adjacent to a wide string literal token, the behavior is undefined... My example did not mix wide and narrow literals, but that's not the point here. Tim Smith wrote: The two strings are concatentated. Indeed, but not in the sense of what one typically thinks of with concatenation (e.g., the "+" operator). Tim Smith wrote: They way you describe it is totally wrong. I respectfully disagree, as it makes perfect sense to me and others I've spoken with about it. Perhaps we are saying the same thing two different ways. Tim Smith wrote: It doesn't just ignore the two quotes as also covered in 2.13.4.3. The compiler sees/stores the two concatenated literals as one single literal. Tim Smith wrote: It doesn't just place the two strings after each other in the EXE. If the two concatenated literals were stored separately, how would the compiler know to find the other piece(s)? It's not like there is a pointer at the end of the first one that points to the start of the second one. Look at some of your latest .exe or .dll files and you'll see that string literals are kept together. Tim Smith wrote: Literal string pooling requires that strings be moved around. Of course, but only when they are

                    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