Why func("abc" "def"); compiles
just stumbled onto a开发者_StackOverflow社区 miss in my code, a function was called like this
func("text1" "text2");
instead of
func("text1", "text2");
The thing is that it actually compiles and runs (MSVC 2008), the two strings are treated as one (ie a call to an overloaded func gets the input "text1text2").
Is this normal standard behaviour (ie. "abc" "def" == "abcdef") or isn't it ?
Yes, this is called string literal concatenation, and is a feature of the C and C++ compiler.
Yes, it's normal behavior. It's useful for having string constants span multiple lines. You must have an overload of "func" somewhere that can accept a single parameter of char*
.
Yes, this is standard behaviour.
Yes, it's useful for building strings based on #define
s.
#define MY_FOLDER "/some/folder/"
#define MY_FILE MY_FOLDER "file.txt"
// expands to "/some/folder/file.txt"
精彩评论