Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm 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 From: "Dave Korn" To: Subject: RE: simple C program crashes at run time Date: Thu, 12 Aug 2004 12:31:38 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit In-Reply-To: <200408121041.MAA00181@gsnet0.lngs.infn.it> Message-ID: X-OriginalArrivalTime: 12 Aug 2004 11:31:39.0484 (UTC) FILETIME=[EF18B9C0:01C4805F] > -----Original Message----- > From: cygwin-owner On Behalf Of user > Sent: 12 August 2004 11:48 > #define TAGLIA 415 > main() > { > > int i, j, k, iran; > unsigned int seed; > float unran; > float mata[TAGLIA][TAGLIA], > matb[TAGLIA][TAGLIA], > matc[TAGLIA][TAGLIA]; 1 float == 4 bytes. 415 * 415 == 172225 elements 3 arrays * 415^2 elements each * 4 bytes == 2066700 bytes I believe that's a bit large for the stack. > It works for TAGLIA < 416 > With TAGLIA = 416 it looks unusually fast and without outputs > with TAGLIA > 416 it crashes: > > sysnaz AT wngsnt ~ > $ ./unlucky.exe > Segmentation fault (core dumped) > > $ more unlucky.exe.stackdump > Exception: STATUS_STACK_OVERFLOW at eip=00401593 And indeed, the system agrees with me. > What does it happen? the same code built on linux doesn't > crashes.. Linux and 'doze reserve different amounts of memory space for the stack when a task starts up (to be precise, when a thread starts up within a task). In particular, the default stack size for a newly-created thread under windoze is 1Mb, which is less than half what you'd need for those arrays. See http://www.google.com/search?hl=en&ie=UTF-8&q=increase+default+thread+stack+ size+site%3Acygwin.com for masses more information. In particular, you may need to recompile your application with the "-Wl,--stack," argument. Here's an example. I took your code and removed the #define TAGLIA, so I could pass it in as a commandline -D flag: dk AT mace /davek/test/cygstack> cat telle.c #include #include #include main() { int i, j, k, iran; unsigned int seed; float unran; float mata[TAGLIA][TAGLIA], matb[TAGLIA][TAGLIA], matc[TAGLIA][TAGLIA]; srand(seed); printf("init start...\n"); /* this should init all elements with pseudo-random float values */ for(i=0;i gcc -o unlucky -DTAGLIA=410 telle.c dk AT mace /davek/test/cygstack> ./unlucky.exe init start... init end..... all done..... dk AT mace /davek/test/cygstack> gcc -o unlucky -DTAGLIA=411 telle.c dk AT mace /davek/test/cygstack> ./unlucky.exe Segmentation fault (core dumped) dk AT mace /davek/test/cygstack> gcc -o unlucky -DTAGLIA=411 telle.c -Wl,--stack,8 192000 dk AT mace /davek/test/cygstack> ./unlucky.exe init start... init end..... all done..... dk AT mace /davek/test/cygstack> gcc -o unlucky -DTAGLIA=444 telle.c -Wl,--stack,8 192000 dk AT mace /davek/test/cygstack> ./unlucky.exe init start... init end..... all done..... dk AT mace /davek/test/cygstack> gcc -o unlucky -DTAGLIA=444 telle.c dk AT mace /davek/test/cygstack> ./unlucky.exe Segmentation fault (core dumped) dk AT mace /davek/test/cygstack> As you can see, for reasons probably relating to different environment variable size, I can only get up to 410 before I get errors; adding the --stack option fixes it. cheers, DaveK -- Can't think of a witty .sigline today.... -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/