Path: utzoo!utgpu!attcan!uunet!mcvax!enea!kth!draken!pk-tle From: pk-tle@nada.kth.se (Tommy Levitte) Newsgroups: comp.lang.c Subject: Re: Are strings local? Keywords: Help! Message-ID: <503@draken.nada.kth.se> Date: 3 Aug 88 09:07:39 GMT References: <644@m10ux.UUCP> Reply-To: pk-tle@nada.kth.se (Tommy Levitte) Organization: The Royal Inst. of Techn., Stockholm Lines: 32 >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? There are two kinds of statics: - External statics. - Internal statics. External statics are defined outside functions, and internal are defined inside functions. External statics are reachable in the whole file, but internal statics are only available in the function in which they are defined. A string constant is an exception to this rule. It is available in the whole file. This means that all your examples where legal. -- ------------------------------------------------------------------------------- Tommy Levitte (pk-tle@draken.nada.kth.se or gizmo@kicki.stacken.kth.se) -------------------------------------------------------------------------------