Path: utzoo!attcan!uunet!taumet!steve From: steve@taumet.com (Stephen Clamage) Newsgroups: comp.lang.c Subject: Re: WEIRD BUG ABOUT EXIT Message-ID: <361@taumet.com> Date: 30 Jul 90 15:15:48 GMT References: <6031@hub.ucsb.edu> Distribution: na Organization: Taumetric Corporation, San Diego Lines: 28 brian@orange.ucsb.edu (Brian Mak) writes: >I encounter a weird bug at the end of my program. I got a segmentation fault >right at the closing bracket of the main(). i.e. if >line 1: main() >line 2: { > . >line N: } >the faults occurs right at line N. >But if I put exit(0) before line N, it exits without error! Two possibilities occur to me: 1. There is an error in your program causing the stack to be overwritten, so that the return from main() doesn't work properly. Calling exit() directly avoids the problem area. The usual error is a wild pointer of some kind: uninitialized pointer, error return not checked for and bogus pointer value used, off-by-one in a loop or array, non-portable assumption about pointers or addresses which was false on this system. With that checklist, you should have no trouble isolating the error :-). 2. Your C runtime environment is nonstandard, in that returning from main() doesn't work. This seems very unlikely, but is easy to check. See what your manual says about returning from main(), and/or try the "hello world" program with no explicit return from main(). -- Steve Clamage, TauMetric Corp, steve@taumet.com