Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This noncompliant code example concatenates wide and narrow string literals. The Although the behavior is undefined in this case. However, it is likely that the programmer 's intention was probably intended to create a wide string literal.

Code Block
bgColor#ffcccc
wchar_t *msg = L"This message is very long, so I want to divide it "
                "into two parts.";

Compliant Solution (

...

Wide String Literals)

If the concatenated string needs to be a wide string literal, each element in the concatenation must be a wide string literal, as in this compliant solution.

Code Block
bgColor#ccccff
wchar_t *msg = L"This message is very long, so I want to divide it "
               L"into two parts.";

Compliant Solution (

...

Narrow String Literals)

If wide string literals are not necessaryunnecessary, it is better to use narrow string literals, as in this compliant solution.

Code Block
bgColor#ccccff
char *msg = "This message is very long, so I want to divide it "
            "into two parts.";

Risk Assessment

Concatenation The concatenation of wide and narrow string literals leads to undefined behavior.

...