Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: local arrays and stack Date: Mon, 23 Mar 2015 09:16:30 -0700 Organization: None to speak of Lines: 28 Message-ID: <87fv8vu1sx.fsf@kst-u.example.com> References: <87k2y7u48c.fsf@kst-u.example.com> <705a5674-dbc9-460a-a72c-50bf1946be01@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: mx02.eternal-september.org; posting-host="c77ff4d35e33d1c939d3461ebde8dd0d"; logging-data="28968"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/8Z8//U6TqpyK95+skVciv" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:k4ZZi/88eOyNNCa7J6Ia22yjXf0= sha1:94clPYe62jAvOdtuYfmd3X4mTxs= Xref: csiph.com comp.lang.c:58760 Bartc writes: > On 23/03/2015 15:42, fir wrote: >> W dniu poniedziałek, 23 marca 2015 16:24:12 UTC+1 użytkownik Keith Thompson napisał: >>> MinGW uses gcc as its compiler. As far as I know, all local non-static >>> objects (i.e., objects with automatic storage duration), including >>> arrays of any size, are allocated on the stack. >>> >> any size? >> >> i thought that large ones are 'silently' moved to static area >> (stack is small, probably 2MB limit usually so how it could contain >> larger arrays? it could be silent move out of stack or compile >> error) (i may be mistaken here)) > > The stack can grow. Large local arrays can also be allocated on the > heap. It's up to the compiler. Does gcc *ever* (generate code to) allocate local non-static arrays on the heap or in static memory? It would have to generate code to explicitly deallocate the array, even in the presence of a goto or longjmp() out of the scope. Certainly a compiler *could* do that, but I've never heard of gcc in particular doing so. -- 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"