Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!uwm.edu!ux1.cso.uiuc.edu!phil From: phil@ux1.cso.uiuc.edu (Phil Howard KA9WGN) Newsgroups: comp.lang.c Subject: Re: Returning pointers to constant strings Keywords: static constant string Message-ID: <1991May6.204518.18499@ux1.cso.uiuc.edu> Date: 6 May 91 20:45:18 GMT References: <21139@brahms.udel.edu> Distribution: na Organization: University of Illinois at Urbana Lines: 38 weave@brahms.udel.edu (Ken Weaverling) writes: >In the local newsgroup at Univ of Del, the consensus was that it would be >a bad idea, due to systems such as Mess/DOS that might use code overlays, >and the constant string might be stored in a code overlay that would not >always be resident. ... >Well, I referred to the *bible* for C, the Kernighan and Ritchie book on C, >second edition (for ANSI C). It says on page 194, section A2.6 ... >A string literal, also called a string constant, is a sequence of characters >surrounded by double quotes, as in "...". A string has type "array of >characters" and storage class *static*. Whether identical strings are >distinct is implementation-defined, and the behavior of a program that >attempts to alter a string literal is undefined. >.... and then the definition of static from section A4.1 ... >Static objects may be local to a block or external to all blocks, but in >either case, retain their values across exit from and reentry to functions >and blocks. >So, from above, I infer that there is nothing wrong with the code above. >Any comments? Is it still bad practice from a style standpoint? Thanks! I personally would infer that the Mess/DOS code overlays are broken unless the implementation ensures that somehow the string constant values are not actually part of the overlaying. Does the code and the static data of a block have to be continguous in memory? -- /***************************************************************************\ / Phil Howard -- KA9WGN -- phil@ux1.cso.uiuc.edu | Guns don't aim guns at \ \ Lietuva laisva -- Brivu Latviju -- Eesti vabaks | people; CRIMINALS do!! / \***************************************************************************/