shared storage for string literals?
Steve Vegdahl
vegdahl at ogicse.cse.ogi.edu
Wed May 29 05:51:29 AEST 1991
The ANSI standard states that two identical string literals may share storage.
Thus, whether the execution of the block:
{ char *a = "hello";
char *b = "hello";
printf("%s", a==b ? "YES" : "NO");
}
prints "YES" is depends on the implementation.
Question: can non-identical substrings share storage if one is a substring
of the other, and they share a common "tail"? In other words, is it legal
for an implementation to print "YES" when executing the following block:
{ char *a = "Say hello";
char *b = "hello";
printf("%s", (a+4)==b ? "YES" : "NO");
}
I find nothing in the standard that gives a definitive answer to this question.
Steve Vegdahl
Adaptive Solutions, Inc.
More information about the Comp.lang.c
mailing list