This is the mail archive of the
mailing list for the Cygwin project.
Re: strange bug that doesn't occur in Linux, OpenBSD or ITS
- From: Dave Korn <dave dot korn dot cygwin at gmail dot com>
- To: cygwin at cygwin dot com
- Date: Fri, 24 Feb 2012 13:02:00 +0000
- Subject: Re: strange bug that doesn't occur in Linux, OpenBSD or ITS
- Authentication-results: mr.google.com; spf=pass (google.com: domain of email@example.com designates 10.180.86.230 as permitted sender) firstname.lastname@example.org; dkim=pass email@example.com
- References: <1329589939.95502.YahooMailNeo@web120301.mail.ne1.yahoo.com>
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
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.
Problem reports: http://cygwin.com/problems.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple