"Jim Strathmeyer" <no************@andrew.cmu.edu> wrote in message
news:Pi**********************************@unix43.a ndrew.cmu.edu...
On Thu, 22 Jul 2004, John Harrison wrote:
On Thu, 22 Jul 2004 15:04:23 -0400 (EDT), Jim Strathmeyer
<no************@andrew.cmu.edu> wrote:
Under what circumstances would closing a istream object (such as
'in.close()') SEGFAULT?
When you have a bug in your program. What else?
All the usual suspects, writing past he end of an array, writing through
a garbage pointer, freeing the same memory twice, etc. etc. All these bugs
can cause anything to happen.
Bugs rarely have any logic. You can rarely say 'well the symptom is
this, therefore the bug must be that', at least that sort of intuition only
comes with much experience.
...right... but why would a SEGFAULT happen inside a library function?
If you've done something 'wrong' (such as some of the things
John mentioned) *anywhere* in your program, it could easily
cause corruption anywhere else in your program, including inside
library code. IMO the best way for tracking down a bug whose source
is unknown and/or not easily reprocible is careful, methodical
testing, and selective removal of (relatively large) sections of
code, testing each version. One a large section has been identified
as the culprit, start removing smaller sections of that section.
Good debuggers also help much.
-Mike