A string literal is a sequence of zero or more multibyte characters enclosed in double quotes (for example, "xyz"
). A wide string literal is the same, except prefixed by the letter 'L'
(for example, L"xyz"
).
At compile time, string literals are used to create an array of static storage duration of sufficient length to contain the character sequence and a null-termination character. It is unspecified whether these arrays are distinct. The behavior is undefined if a program attempts to modify string literals but frequently results in an access violation because string literals are typically stored in read-only memory. See also undefined behavior 30 of Annex J of C99.
...
Noncompliant Code Example
In this noncompliant code example, a string literal is passed to the mktemp (pointer to non-const
) parameter of the POSIX function modifies its string argument mkstemp()
, which then modifies the characters of the string literal.
Code Block | ||
---|---|---|
| ||
char *fname; fname = mktempmkstemp("/tmp/edXXXXXX"); |
Compliant Solution
...