Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!ukma!nrl-cmf!ames!hao!oddjob!gargoyle!ihnp4!homxb!mtuxo!mtune!codas!usfvax2!pdn!pdnbah!reggie From: reggie@pdnbah.UUCP (George Leach) Newsgroups: comp.lang.c Subject: Re: How are local vars allocated? Message-ID: <1818@pdn.UUCP> Date: Tue, 24-Nov-87 08:14:36 EST Article-I.D.: pdn.1818 Posted: Tue Nov 24 08:14:36 1987 Date-Received: Sat, 28-Nov-87 10:38:29 EST References: <9367@mimsy.UUCP> <1633@megatest.UUCP> <1987Nov22.085210.20641@sq.uucp> Sender: usenet@pdn.UUCP Reply-To: reggie@pdnbah.UUCP (George Leach) Organization: Paradyne Corporation, Largo, Florida Lines: 32 In article <1987Nov22.085210.20641@sq.uucp> msb@sq.UUCP (Mark Brader) writes: >There have been several followups regarding the code: > for (;;) { > int k; > ... > } >but I think they have each either left out an important point, or wandered >at length into side issues. So let me try. [stuff deleted concerning allocation and deallocation of the variable k and what might actually be implemented by a compiler....... >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; ^^^^^^ ... } George W. Leach Paradyne Corporation {gatech,rutgers,attmail}!codas!pdn!reggie Mail stop LF-207 Phone: (813) 530-2376 P.O. Box 2826 Largo, FL 34649-2826