开发者

Why func("abc" "def"); compiles

开发者 https://www.devze.com 2023-04-05 01:08 出处:网络
just stumbled onto a开发者_StackOverflow社区 miss in my code, a function was called like this func(\"text1\" \"text2\");

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 #defines.

#define MY_FOLDER "/some/folder/"
#define MY_FILE   MY_FOLDER "file.txt"
// expands to "/some/folder/file.txt"
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号