Newsgroups: comp.lang.c Path: utzoo!henry From: henry@zoo.toronto.edu (Henry Spencer) Subject: Re: shared storage for string literals? Message-ID: <1991May29.164513.12911@zoo.toronto.edu> Date: Wed, 29 May 1991 16:45:13 GMT References: <21996@ogicse.ogi.edu> Organization: U of Toronto Zoology In article <21996@ogicse.ogi.edu> vegdahl@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@zoo.toronto.edu utzoo!henry