Are strings local?
Duke Robillard
rgr at m10ux.UUCP
Tue Aug 2 05:43:59 AEST 1988
I've got a question about string constants. According to the first
edition of K&R, stuff of the form "this is a string" is static (page 181).
This means they are "local to a block" (definition of static--page 182).
Okay, so does this mean that you can't do this:
char *some_function()
{
char *ptr;
ptr= "string";
return(ptr);
}
It seems to me that "string" would only be defined inside some_function.
Is that right, or am I missing something subtle?
What about this:
char *some_function()
{
char *ptr;
ptr= "string";
another_function(ptr);
}
Again, since another_function is not in the same block and "string" is
"local to a block" this would seem illegal. But then so would:
char *some_function()
{
another_function("string");
}
right? And we know that's okay, cause printf does it. What's the
story?
P.S. If this is dumb, please just ignore me, rather than flaming.
Thanks in advance.
--
+------
| Duke Robillard
| AT&T Bell Labs {backbone!}att!m10ux!rgr
| Murray Hill, NJ rgr at m10ux.ATT.COM
More information about the Comp.lang.c
mailing list