Defect Report #080

Submission Date: 03 Dec 93
Submittor: WG14
Source: Clive Feather
Question
Item 17 - merging of string constants
Consider the following code:
char *s1 = "abcde" + 2;
char *s2 = "cde";

Can the expression (s1 == s2) be non-zero? Is the answer different if the first string literal is replaced by the two literals "ab" "cde" (because then there are identical string literals)?
Response
When the last paragraph of subclause 6.1.4 refers to ``string literals'' it is referring to the static arrays created in translation phase 7 as specified in the previous paragraph. Although the current wording of the C Standard may imply that only completely identical arrays need not be distinct, this was not the Committee's intent.
Correction
In subclause 6.1.4, page 31, change the last paragraph of Semantics (before the Example) from:
Identical string literals of either form need not be distinct. If the program attempts to modify a string literal of either form, the behavior is undefined.
to:
These arrays need not be distinct provided their elements have the appropriate values. If the program attempts to modify such an array, the behavior is undefined.
Previous Defect Report < - > Next Defect Report