Mail Archives: djgpp/2004/08/12/11:45:35
"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 -