Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.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 12:48:17 -0700 Organization: None to speak of Lines: 35 Message-ID: <877fu7trzy.fsf@kst-u.example.com> References: <87k2y7u48c.fsf@kst-u.example.com> <705a5674-dbc9-460a-a72c-50bf1946be01@googlegroups.com> <87bnjjty2r.fsf@kst-u.example.com> <56cd397c-bac6-4eac-ab5a-5548a9473140@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="c77ff4d35e33d1c939d3461ebde8dd0d"; logging-data="20555"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+kqnpIyfCQImAda3kMkkl1" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:0Lvsjvir6Hb5IyQYAjqHe0Ovwyw= sha1:HAT3bWL4DiNS/Vgyx6OE0qKw9E4= Xref: csiph.com comp.lang.c:58782 Xcott Craver writes: > On Monday, March 23, 2015 at 1:37:23 PM UTC-4, Keith Thompson wrote: >> Xcott Craver <@> writes: >> > I can declare a 160MB array and see it on the stack. It's just a matter >> > of subtracting the relevant offset from the stack pointer. >> >> Using what implementation? > > 64-bit OSX: > > #define LEN 40000000 > int main( void ) { > int array [LEN]; .... > > (lldb) disas --name main > a.out`main at tester.c:12: > a.out[0x100000ec0]: pushq %rbp > a.out[0x100000ec1]: movq %rsp, %rbp > a.out[0x100000ec4]: subq $0x9896820, %rsp <---- 160000032 bytes > > The ulimit command tells me that I apparently have an 8192K soft limit, and a > 65532K hard limit on the stack. However, I can declare gigabyte-sized arrays, > and dissassembly just shows the function subtracting insane amounts from the > stack pointer. I tried something similar on my system (Linux Mint, x86_64). When I just declared the array, the program compiled and ran without error. When I assigned a value to an element near the end of the array, it died with a segmentation fault. -- 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"