strange bug that doesn't occur in Linux, OpenBSD or ITS
Dave Korn
dave.korn.cygwin@gmail.com
Fri Feb 24 13:02:00 GMT 2012
On 18/02/2012 18:32, Jeremiah Bishop wrote:
> the bash commands used are: 1) gcc "cygwin puzzle.c"
>
> 2) ./a.out a b
> Now either version used on a file with a shorter set of lines, works just
> fine but strangely, that single digit difference aborts the program without
> throwing any error on the sample input or text files with similarly long
> lines.
Your program is overflowing the stack. The default amount of stack space
allocated by windows for a program is 2MB, but you can increase it using the
"-Wl,--stack,<SIZE>" option (GCC passes -Wl options through to the linker, see
'man ld' for details of the --stack option). I found your program could run
to completion when I compiled it with "-Wl,--stack,10000000" for a ~10MB stack.
However the better fix would not to be to nest forty-three thousand
recursive stack calls. Your code is very slow because it starts at the
beginning of the list every time and recursively works its way to the end,
costing a function call and stack frame for every node along the way. Iterate
if you really have to do it that way, or even better, keep a pointer to the
end node of the list and just go straight there.
cheers,
DaveK
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
More information about the Cygwin
mailing list