Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!sq!msb From: msb@sq.UUCP Newsgroups: comp.lang.c Subject: Re: How are local vars allocated? Message-ID: <1987Nov27.014354.11406@sq.uucp> Date: Fri, 27-Nov-87 01:43:54 EST Article-I.D.: sq.1987Nov27.014354.11406 Posted: Fri Nov 27 01:43:54 1987 Date-Received: Sun, 29-Nov-87 14:40:37 EST References: <9367@mimsy.UUCP> <1633@megatest.UUCP> <1987Nov22.085210.20641@sq.uucp> <1818@pdn.UUCP> Reply-To: msb@sq.UUCP (Mark Brader) Organization: SoftQuad Inc., Toronto Lines: 17 Checksum: 54668 > >But the value of "k" is NOT guaranteed to be retained from one iteration > >to the next, and you must not assume it will be. If you want that, you > >have to declare "k" in a larger scope including the for-header. > > Or you can declare it static: > for (;;) { > static int k; > ... > } True, but then there's only one copy of k even if the function is re-called recursively(). If that isn't a problem, static is fine. I prefer not to limit potential recursions unnecessarily. Mark Brader "Male got pregnant -- on the first try." utzoo!sq!msb Newsweek article on high-tech conception msb@sq.com November 30, 1987