From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,35f176bbf8db98d9 X-Google-Attributes: gidfee84,public From: Dan.Pop@cern.ch (Dan Pop) Subject: Re: problem allocating large static arrays in C??? Date: 1996/11/11 Message-ID: #1/1 X-Deja-AN: 195965987 sender: news@news.cern.ch (USENET News System) x-nntp-posting-host: ues5.cern.ch references: <55tbqt$77f@post.gsfc.nasa.gov> organization: CERN European Lab for Particle Physics newsgroups: comp.unix.osf.osf1 In <55tbqt$77f@post.gsfc.nasa.gov> fish@daacdev1.stx.com ("John R. Vanderpool") writes: >DEC OSF1 V3.0 seems to not be able to allocate a single 10MB >static array. am i missing something obvious? Yes: the definition of 'static array' in C. >statically it fails: > >int main() >{ >char total[5004][2168]; total is an automatic array, not a static array. C has the keyword 'static'. Guess why? >printf( "foobar\n" ); Using printf (or any other variadic function) without a prototype in scope invokes undefined behaviour. >} > >Memory fault(coredump) Increase your stacksize limit and even the version with the automatic array will work. Using large automatic arrays is a bad idea in the first place, however. >it seems to work dynamically though: > >#include > >int main() >{ >char *total; > >total=(char *)malloc( 5004*2168 ); Without your silly cast, the compiler would have warned you that you're doing the wrong thing here: malloc is not a function returning int (and it doesn't take an int argument) so a proper declaration is a must. Dan -- Dan Pop CERN, CN Division Email: Dan.Pop@cern.ch Mail: CERN - PPE, Bat. 31 1-014, CH-1211 Geneve 23, Switzerland