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