Syntax Error NOT!
-
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 -
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.ukJeremy 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
-
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 -
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
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 -
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.ukThere'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
-
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
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.
-
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.
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
-
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
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.
-
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.
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