Versions Compared

Key

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

According to MISRA 2008, concatenation of wide and narrow string literals leads to undefined behavior. This was once considered implicitly undefined behavior until C90 [ISO/IEC 9899:1990]. However, C99 defined this behavior [ISO/IEC 9899:1999], and C11 further explains in section Section 6.4.5, paragraph 5 [ISO/IEC 9899:2011]:

...

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
langc
wchar_t *msg = L"This message is very long, so I want to divide it "
               L"into two parts.";

...

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

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

...