Path: utzoo!attcan!uunet!lll-winken!lll-tis!helios.ee.lbl.gov!nosc!ucsd!rutgers!att!whuts!homxb!mhuxu!m10ux!rgr From: rgr@m10ux.UUCP (Duke Robillard) Newsgroups: comp.lang.c Subject: Are strings local? Keywords: Help! Message-ID: <644@m10ux.UUCP> Date: 1 Aug 88 19:43:59 GMT Reply-To: rgr@m10ux.UUCP (Duke Robillard) Organization: AT&T Bell Labs, Murray Hill Lines: 43 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@m10ux.ATT.COM