Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Array allocated on stack or heap Date: Fri, 17 Mar 2017 11:26:27 -0700 Organization: None to speak of Lines: 24 Message-ID: References: <6f1ncc9c5jto8p8tdes73rfpts1ub37td5@4ax.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="a62e3c498ac96524fc545ef94a9038ec"; logging-data="15061"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19242GhUmamESOr9Ll8PJsc" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:ObhlgI5SOLCi9nxTxeq9ivPrdgg= sha1:tg4UNWeGnNWcMWCbvjjGA70iGhw= Xref: csiph.com comp.lang.c:106373 Mark Storkamp writes: [...] > And to add to what Barry said, if you had > > void check_array() { > static int a[20000]; > ..... > } > > then by common usage of the terms stack and heap, a would be allocated > in the heap. (All usual conditions, exceptions &c apply). Incorrect. In typical implementations, objects with static storage (defined with the "static" keyword and/or at file scope) are allocated in a separate region of memory that's set up when the program is loaded. It continues to be allocated during the entire execution of the program. This is distinct from both the "stack" and the "heap" (the latter is allocated and deallocated by calls to malloc, free, and equivalents). -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"