shared storage for string literals?

Henry Spencer henry at zoo.toronto.edu
Thu May 30 02:45:13 AEST 1991


In article <21996 at ogicse.ogi.edu> vegdahl at ogicse.cse.ogi.edu (Steve Vegdahl) writes:
>... standard states that two identical string literals may share storage.
>Question: can non-identical substrings share storage if one is a substring
>of the other, and they share a common "tail"? ...

It appears to me that a very strict reading of the standard outlaws such
sharing.  The description (3.1.4) of what a string literal points to is
in terms of each string literal initializing an anonymous array "just
sufficient to contain the sequence", and the only exception granted is
for identical string literals.  The results of modifying one are undefined,
but pointer comparison can still be used to notice such things, so the
"as if" rule is not applicable.

I doubt that this was the intent of X3J11, and I suggest that it is most
unwise for code to depend on it.
-- 
"We're thinking about upgrading from    | Henry Spencer @ U of Toronto Zoology
SunOS 4.1.1 to SunOS 3.5."              |  henry at zoo.toronto.edu  utzoo!henry



More information about the Comp.lang.c mailing list