Message-ID: <3306B5A8.41@rangenet.com> Date: Sun, 16 Feb 1997 01:22:16 -0600 From: Dan Hedlund Reply-To: markiv AT rangenet DOT com Organization: Range Net MIME-Version: 1.0 To: nikki CC: djgpp AT delorie DOT com Subject: Re: boo hoo. my code crashes. References: <5e5d6n$fda AT flex DOT uunet DOT pipex DOT com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit nikki wrote: > > ok i give up, i have no idea what is wrong with the below code. it compiles > fine on sunos and linux but when i compile it with djgpp it gets to testpoint > 'a' and then hangs. ie the initialising of the struct seems to be hanging the > machine. it never gets as far as printing 'b' :( > > can anyone see what i've done wrong here? i'm out of ideas :( > (it's not something to do with the _packed_ attribute is it perchance?) > > regards, > nik > > --- > > struct node { > unsigned int frequency; > struct node *next; /* used to create an ordered list > struct node *zero_child, *one_child; > unsigned short symbol; > char *code; /* a string of 0's and 1's */ > }; > > int huffman_encode () > { > struct node *histogram[NUM_SYMBOL_VALUES]; > struct node *huffman_tree; > int encoded_stream_length; > unsigned int i; > printf("a\n"); > /* initialize histogram */ > for (i=0; i printf("b\n"); > } > > (num_symbol_values is #define'd as 0x10000) Here's the problem. Your putting an array of 65536 pointers (256 kb) on the stack. You've got 3 options: 1. Make histogram a global variable 2. Use "struct note *(*histogram [NUM_SYMBOL_VALUES]) = malloc (sizeof (node) * NUM_SYMBOL_VALUES);" 3. Increase the stack size. I would recommend option number 2. > the program prints 'a' then hangs. even ctrl-c won't abort and i have to > reboot ;( > under linux and sunos this compiles and runs just fine. > > -- > Graham Tootell > nikki AT gameboutique DOT com -- ***** *** ** ** Dan M. Hedlund ** ** ***** *** ** ** ** ** ** **** ** http://www.rangenet.com/markiv ** ** ** ** ** ** ** ** ** ******* ** **** ** ** ** ** ** *** ** ** ** ** ** ** ***** ** ** ** **