Why allow concatenation of string literals?
Posted
by Caspin
on Stack Overflow
See other posts from Stack Overflow
or by Caspin
Published on 2010-03-24T00:08:04Z
Indexed on
2010/03/24
0:13 UTC
Read the original article
Hit count: 770
I recently got bit by a subtle bug.
char ** int2str = {
"zero", // 0
"one", // 1
"two" // 2
"three",// 3
nullptr };
assert( values[1] == "one"_s ); // passes
assert( values[2] == "two"_s ); // fails
If you have godlike code review powers you'll notice I forgot the ,
after "two"
.
After the considerable effort to find that bug I've got to ask why would anyone ever want this behavior?
I can see how this might be useful for macro magic, but then why is this a "feature" in a modern language like python?
Have you ever used string literal concatenation in production code?
© Stack Overflow or respective owner