delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2002/07/18/23:15:34

From: "Eric G. Miller" <egm2 AT jps-nospam DOT net>
Subject: Re: Recursions and Static declarations....?Is this wrong...
Newsgroups: comp.os.msdos.djgpp,comp.lang.c
Message-ID: <pan.2002.07.19.02.42.27.38268.9227@jps-nospam.net>
References: <5a91d0ef DOT 0207181004 DOT 49e67056 AT posting DOT google DOT com>
User-Agent: Pan/0.11.3 (Unix)
Mime-Version: 1.0
X-Comment-To: "Pradeepto K Bhattacharya" <pradeeptob AT yahoo DOT com>
Lines: 53
Date: Fri, 19 Jul 2002 02:39:59 GMT
NNTP-Posting-Host: 216.119.44.77
X-Complaints-To: abuse AT earthlink DOT net
X-Trace: newsread1.prod.itd.earthlink.net 1027046399 216.119.44.77 (Thu, 18 Jul 2002 19:39:59 PDT)
NNTP-Posting-Date: Thu, 18 Jul 2002 19:39:59 PDT
Organization: EarthLink Inc. -- http://www.EarthLink.net
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

In <5a91d0ef DOT 0207181004 DOT 49e67056 AT posting DOT google DOT com>, Pradeepto K Bhattacharya wrote:

> Hello 
>     Well I tried to write this function...it is crashing the computer
> If i compile it with BorlandC++ 3 , DevC++ 4, LCC-Win32...but it works
> pretty fine If I use Djgpp.
>     This is the funtion................

Something tells me it isn't.  I can't see why you're even using recursion
here. And what happens the second time you want to call this function?

> void do_mat(char matrix[][COLS])
> {
>   static int si=0;
>   static int sj=0;
> 
>   while(si<ROWS)
>   {
>    while(sj<COLS)
>    {
>      matrix[si][sj]='o';
>      if(++sj==COLS)
>      {
>        sj=0;
>        break;
>      }
>      else
>      do_mat(matrix);
>    }
>    si++;
>   }
> }

void do_mat (char matrix[ROWS][COLS])
{
    int i, j;
    for (i = 0; i < ROWS; i++)
        for (j = 0; j < COLS; j++)
            matrix[i][j] = 'o';
}

>   Can I not use Static with recursions...why is it only working with
> Djgpp and not with others...
>    All help will be appretiated.Thanks in advance.

Different compilers will generate different code... You're probably
running out of stack space.  The compilers probably can't optimize
the function to avoid keeping all that state on the stack.  You could
probably keep recursion and eliminate the static variables:

  void do_mat (char matrix[ROWS][COLS], int row_pos, int col_pos);

You fill in the definition...

- Raw text -


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