Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!rutgers!princeton!udel!new From: new@udel.EDU (Darren New) Newsgroups: comp.lang.c Subject: Re: How are local vars allocated? Message-ID: <707@louie.udel.EDU> Date: Sun, 15-Nov-87 13:26:32 EST Article-I.D.: louie.707 Posted: Sun Nov 15 13:26:32 1987 Date-Received: Mon, 16-Nov-87 05:43:24 EST References: <189@dalcsug.UUCP> <7401@prls.UUCP> Sender: usenet@udel.EDU Reply-To: new@udel.EDU (Darren New) Organization: University of Delaware Lines: 17 In article <7401@prls.UUCP> gardner@prls.UUCP (Robert Gardner) writes: >Is there any danger of stack overflow with the following construct: >[code with allocation of local inside a for-loop block here] >In other words, is k allocated only once at the beginning of the >procedure containing this construct, or is it allocated each time >the {} block is entered? Is the answer implementation dependent? > >Robert Gardner Most compilers I've seen allocate it once at the beginning of the function. If there are multiple blocks with local variables, these definitions overlap. EG: {int k; k = 3;} {int w; w = 77;} would put K and W in the same place. However, even if the variable is allocated on each entry, it will be deallocated at the end of each loop. Thus, no stack problems. (Of course, recursive functions are something else.) Darren New @ UDel