delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2004/08/12/11:45:35

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
From: "John Hanley" <jdhanley AT telusplanet DOT net>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: program hanging
Date: Thu, 12 Aug 2004 09:25:49 -0600
Organization: University of Alberta
Lines: 89
Message-ID: <1092324277.615039@proxy2.srv.ualberta.ca>
References: <1092258885 DOT 100659 AT proxy2 DOT srv DOT ualberta DOT ca> <7105-Thu12Aug2004064431+0300-eliz AT gnu DOT org>
NNTP-Posting-Host: proxy2.srv.ualberta.ca
X-Trace: tabloid.srv.ualberta.ca 1092324279 28056 129.128.5.161 (12 Aug 2004 15:24:39 GMT)
X-Complaints-To: abuse AT ualberta DOT ca
NNTP-Posting-Date: Thu, 12 Aug 2004 15:24:39 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4522.1200
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200
Cache-Post-Path: proxy2.srv.ualberta.ca!unknown AT d199-126-23-72 DOT abhsia DOT telus DOT net
X-Cache: nntpcache 3.0.1 (see http://www.nntpcache.org/)
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

"Eli Zaretskii" <eliz AT gnu DOT org> wrote in message
news:7105-Thu12Aug2004064431+0300-eliz AT gnu DOT org...
> > My DOS program compiled under DJGPP seems to be hanging.  When I try
running
> > it, it doesn't even get to the first printf statement in the program.
When
> > I debugged it with gdb, the first time it stepped through ok, the second
> > time I set a breakpoint for line 1 and it didn't even make it there.
How
> > does  a program hang before it gets to the first line of the program?
>
> One possibility is that you have large automatic arrays or structures
> that overflow the run-time stack.

One other thing I noticed comes from this segment of code:

rtn=f_eat_spaces(param);
          /* eat up white spaces and multiple \n characters
           * until an alphanumeric or EOF encountered */
          while(rtn==0)
          {
          rtn=f_eat_spaces(param);
          }

          /* if it's EOF, we're done with parameter file */
          if(rtn==EOF)
           break;

This is inside a larger while loop.. If I take out the while(rtn==0) loop,
the program works fine.  All this is doing
is calling a function to eat up white spaces in the file.  When it returns
0, it
encountered \n.  I want to eat up newlines too (in this part of the program
in case
someone has a double space in there by accident.  f_eat_spaces() will return
either 1 if
it hits an alphanum char or EOF if it hits EOF:

int f_eat_spaces(FILE * f)
{
 int rtn=2;
     char c;

     /* loop until either an EOF is encountered
      * or an alphanumeric character or \n is found.
      *
      * Return:
      * 1 - if alphanumeric char is encountered
      * 0 - if \n is encountered
      * EOF - if EOF is encountered
      */
     while(rtn!=EOF)
     {
      rtn=fscanf(f,"%c",&c);

          /* if we come across an alphanumeric
           * character, we put it back and break
           * out of the loop.*/
          if(isalnum(c))
          {
           rtn=1;
           ungetc(c,f);
               break;
          }
          else if(c=='\n')
          {
            rtn=0;
               break;
          }

     }
     return rtn;
}

The line of code that hangs (the malloc) is called substantially before this
section of code is come across at all.  But I do know taking the above
while(rtn==0) out allows it to work (for whatever reason).

This must be some sort of low level issue or something, because my logic
can't figure out what difference a while loop would make.

Any other suggestions?

Thanks!

John


- Raw text -


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