Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!apple!agate!e260-1c.berkeley.edu!c60b-1eq From: c60b-1eq@e260-1c.berkeley.edu (Noam Mendelson) Newsgroups: comp.lang.c Subject: Re: doing nasty things with internal static variables Keywords: C, crossreference Message-ID: <1991Mar20.054445.14264@agate.berkeley.edu> Date: 20 Mar 91 05:44:45 GMT References: <1991Mar19.164037.7421@intellistor.com> <1991Mar19.183920.18911@rice.edu> Sender: usenet@agate.berkeley.edu (USENET Administrator) Distribution: usa Organization: University of California, Berkeley Lines: 21 In article <1991Mar19.183920.18911@rice.edu> fontenot@comet.rice.edu (Dwayne Jacques Fontenot) writes: >I have found myself doing this because it works, but I am curious if it >is a common practice or if it is highly likely to get me into trouble: > >char *foo() >{ > static char string[64]; > > ... > return(string); >} This is fine. Since the area of memory occupied by the variable string is guaranteed not to be touched, you can assume that string will have the same value until it is directly modified. I, in fact, use this construct all the time. It is extremely convenient. =============================================================== Noam Mendelson | "I haven't lost my mind, c60b-1eq@web.Berkeley.EDU | it's backed up on tape University of California at Berkeley | somewhere."