← Home ← Back to /g/

Thread 105916458

15 posts 8 images /g/
Anonymous No.105916458 [Report] >>105916601 >>105916745 >>105917058 >>105917471
>Adjacent string literals are concatenated in C/C++
const char* str1 = "This is" "a" "single" "string";
const char* strt2 = "So"
"is"
"this";

literally for what reason? just to make programatically finding string literals a little bit more annoying?
Anonymous No.105916517 [Report] >>105916829
"probably so \
that \
you don't have to \
do \
this"
Anonymous No.105916551 [Report] >>105916845 >>105917129
What I find worse in C++ is the fact that the comma is an overloadable operator.
Anonymous No.105916601 [Report]
>>105916458 (OP)
>just to make programatically finding string literals a little bit more annoying?
Yeah it's to fuck with you personally and not so people can generate strings with the preprocessor.
Anonymous No.105916745 [Report] >>105916829 >>105917058 >>105917854
>>105916458 (OP)
> string literals concatenated
It’s not guaranteed.
I just did this, and my second string was a “guard” pattern.
I wrote over the first string bounds, printed out my guard… looked the exact same.
Disassembled with /Fa and lo and behold, the compiler put some extra C++ junk in there between the strings. Not even alignment padding (you’d expect the second string might start on a 32, 64, or 128-bit boundary for simd memxxx operations.
Anonymous No.105916829 [Report] >>105917497 >>105917854
>>105916517
Why are you splitting it up between lines to begin with?
>for formatting reasons!
damn that's crazy, maybe this isn't the right way to go about the problem, and #embed should have been in since fuckin C89??

>>105916745
Got a godbolt?
Anonymous No.105916845 [Report] >>105917384
>>105916551
lol? what's the fucking usecase?
Anonymous No.105916876 [Report]
what does 結城晴 have to do with this?
Anonymous No.105917058 [Report] >>105917403 >>105917497 >>105917854
>>105916745
Got a pic? genuinely curious about this behaviour

>>105916458 (OP)
Its a feature, one that I have used multiple times. Maybe try making something other than a script next time?
Anonymous No.105917129 [Report]
>>105916551
so long as ; is not overloadable everythings fine
Anonymous No.105917384 [Report]
>>105916845
I just used a prolog dcg over a token stream to do:
string_literals([Literal|Literals]) --> string_literal(Literal), string_literals(Literals).
string_literals([]) --> [].


where string_literal is another dcg that handles a single string literal. it's trivial, but annoying to have to handle additional cases because people like you are too retarded to read a single-line string with whitespace characters like a normal fucking programmer.
Anonymous No.105917403 [Report]
>>105917058
I just used a prolog dcg over a token stream to do:
string_literals([Literal|Literals]) --> string_literal(Literal), string_literals(Literals).
string_literals([]) --> [].


where string_literal is another dcg that handles a single string literal. it's trivial, but annoying to have to handle additional cases because people like you are too retarded to read a single-line string with whitespace characters like a normal fucking programmer.
Anonymous No.105917471 [Report]
>>105916458 (OP)
It simplifies preprocessor fuckery.
Wait until you learn about multi-character literals in C.
Anonymous No.105917497 [Report]
>>105916829
>>105917058
The two strings are defined consecutively and looks like OP’s example. They weren’t const though.
Anonymous No.105917854 [Report]
>>105916745
>>105916829
>>105917058
Oops I was wrong, it’s not doing that.
The extra junk was between the first string and the second string. Not the concatenated string.
Picrel is the extra junk you might get between OPs str1 and strt2, which was still surprising