X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=-2.6 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW X-Spam-Check-By: sourceware.org Received-SPF: pass (google.com: domain of dave DOT korn DOT cygwin AT gmail DOT com designates 10.180.86.230 as permitted sender) client-ip=10.180.86.230; Authentication-Results: mr.google.com; spf=pass (google.com: domain of dave DOT korn DOT cygwin AT gmail DOT com designates 10.180.86.230 as permitted sender) smtp.mail=dave DOT korn DOT cygwin AT gmail DOT com; dkim=pass header.i=dave DOT korn DOT cygwin AT gmail DOT com Message-ID: <4F478A48.9000207@gmail.com> Date: Fri, 24 Feb 2012 13:02:00 +0000 From: Dave Korn User-Agent: Thunderbird 2.0.0.17 (Windows/20080914) MIME-Version: 1.0 To: cygwin AT cygwin DOT com Subject: Re: strange bug that doesn't occur in Linux, OpenBSD or ITS References: <1329589939 DOT 95502 DOT YahooMailNeo AT web120301 DOT mail DOT ne1 DOT yahoo DOT com> In-Reply-To: <1329589939.95502.YahooMailNeo@web120301.mail.ne1.yahoo.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT 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 > 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," 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