WEIRD BUG ABOUT EXIT
Stephen Clamage
steve at taumet.com
Tue Jul 31 01:15:48 AEST 1990
brian at 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 at taumet.com
More information about the Comp.lang.c
mailing list