* problem allocating large static arrays in C???
@ 1996-11-07 5:00 "John R. Vanderpool"
1996-11-11 5:00 ` Dan Pop
0 siblings, 1 reply; 2+ messages in thread
From: "John R. Vanderpool" @ 1996-11-07 5:00 UTC (permalink / raw)
DEC OSF1 V3.0 seems to not be able to allocate a single 10MB
static array. am i missing something obvious?
i don't read this newsgroup regularly so could i get an email
reply if you follow-up...
thanx,
fish
statically it fails:
int main()
{
char total[5004][2168];
printf( "foobar\n" );
}
Memory fault(coredump)
it seems to work dynamically though:
#include <stdio.h>
int main()
{
char *total;
total=(char *)malloc( 5004*2168 );
if( total == NULL )
perror( "malloc" );
printf( "foobar\n" );
foobar
--
"it all looks fine to the naked eye,
but it don't really happen that way at all..." PT
John R. <>< Vanderpool <fish@daacdev1.stx.com> NASA/GSFC/HSTX
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: problem allocating large static arrays in C???
1996-11-07 5:00 problem allocating large static arrays in C??? "John R. Vanderpool"
@ 1996-11-11 5:00 ` Dan Pop
0 siblings, 0 replies; 2+ messages in thread
From: Dan Pop @ 1996-11-11 5:00 UTC (permalink / raw)
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 <stdio.h>
>
>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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1996-11-11 5:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1996-11-07 5:00 problem allocating large static arrays in C??? "John R. Vanderpool"
1996-11-11 5:00 ` Dan Pop
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox