Returning pointers to constant strings

Phil Howard KA9WGN phil at ux1.cso.uiuc.edu
Tue May 7 06:45:18 AEST 1991


weave at 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 at ux1.cso.uiuc.edu   |  Guns don't aim guns at  \
\ Lietuva laisva -- Brivu Latviju -- Eesti vabaks  |  people; CRIMINALS do!!  /
 \***************************************************************************/



More information about the Comp.lang.c mailing list