cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1997/02/16/02:39:47

Message-ID: <3306B5A8.41@rangenet.com>
Date: Sun, 16 Feb 1997 01:22:16 -0600
From: Dan Hedlund <markiv AT rangenet DOT com>
Reply-To: markiv AT rangenet DOT com
Organization: Range Net
MIME-Version: 1.0
To: nikki <nikki AT gameboutique DOT co>
CC: djgpp AT delorie DOT com
Subject: Re: boo hoo. my code crashes.
References: <5e5d6n$fda AT flex DOT uunet DOT pipex DOT com>

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<NUM_SYMBOL_VALUES; i++) histogram[i]= (struct node *) NULL;
> 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
 ** **    *****  ***   **       <markiv AT rangenet DOT com>
 **  **  **   ** ****  **       http://www.rangenet.com/markiv
 **   ** **   ** ** ** **
 **   ** ******* **  ****
 **  **  **   ** **   ***
 ** **   **   ** **    **
*****    **   ** **    **

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019