Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

standards

just stumbled onto a 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 ?

like image 823
Valmond Avatar asked Mar 02 '26 10:03

Valmond


2 Answers

Yes, this is called string literal concatenation, and is a feature of the C and C++ compiler.

like image 146
Chriszuma Avatar answered Mar 04 '26 22:03

Chriszuma


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*.

like image 23
James Johnston Avatar answered Mar 04 '26 23:03

James Johnston



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!