This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Segmentation fault Causes


.. Most of core dumping signals indicate bad pointer adresses to your outputs/inputs. Check that your program is not trying to access a memory location 
outside its address.  Bad use of pointers cause bus errors and segmentation violations are typically
out-of-bounds array references, and/or references through uninitialized or
mangled pointers.  Look very closely in your program for bizarre things like
that.  A frequent example of bad use of pointers adress in C is:

        int b;
        scanf("%d", b);

When compiled, you will have the "segmentation fault" signal. Instead, with the correct version:

        int c;
        scanf("%d", &c);

No "segmentation fault message(core file) is given(generated). 

In  C++, a typical example is:

        int* q=new int[150];
        cout<< q[100];

instead of the correct version:

        int* Q=new int[200];
        cout << Q[199]

Good Kuck..

En réponse à Daniel Bolgheroni <dab__ at uol dot com dot br>:

> What are the causes that a program can give an error "Segmentation fault
> (core dumped)"?
> 
> I'm compiling a program I'm writing but I getting some of this error
> messages executing it. I looked into gcc FAQ and gcc 2.95 manual, but I
> found no references to this problem.
> 
> I'm using the following version of gcc:
> 
> gcc version 2.95.3 20010315 (release) (NetBSD nb3)
> 
> Thank you.
> 
> 
> 



                      DIKANDÉ ALAIN MOÏSE
Present: CERPEMA, Département de Physique, fac. Sciences, Univ. Sherbrooke J1k-2R1 
Québec, Canada. tel: (819)821-8000 ext. 3043.
Permanent: Département de Physique, Faculté des Sciences, Université de Douala BP 24157 Douala, Cameroun.

"Le mépris des autres et des choses, plutôt que nous grandir, nous rabaisse et 
met en péril notre capacité de compréhension du monde et de l' humanité". 
Albert Einstein.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]