Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!VAX1.CC.UAKRON.EDU!mcs.kent.edu!usenet.ins.cwru.edu!abvax!iccgcc!browns From: browns@iccgcc.decnet.ab.com (Stan Brown) Newsgroups: comp.lang.c Subject: Re: doing nasty things with internal static variables Message-ID: <3898.27e8ade6@iccgcc.decnet.ab.com> Date: 21 Mar 91 17:58:14 GMT References: <1991Mar19.164037.7421@intellistor.com> <1991Mar19.183920.18911@rice.edu> Distribution: usa Lines: 26 In article <1991Mar19.183920.18911@rice.edu>, fontenot@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); > } > > I am concerned about this because though I know that that static variable > is guaranteed to always be there for the function containing it, it is > not really guaranteed to be there (in memory) at any other time > (correct me if I'm wrong). This is one time where you might be glad to be wrong. Any variable declared as static is guaranteed to stay around for the entire execution of the program. BTW, the parentheses in your return statement are not necessary. My opinions are mine: I don't speak for any other person or company. email (until 91/4/30): browns@iccgcc.decnet.ab.com Stan Brown, Oak Road Systems, Cleveland, Ohio, USA +1 216 371 0043