Segmentation Fault !!!


by karthik3k
Tags: fault, segmentation
karthik3k
karthik3k is offline
#1
Mar16-04, 10:01 AM
P: 151
What does it mean?
I often get that in GCC.
How to overcome that ?
plz help!
Phys.Org News Partner Science news on Phys.org
Cougars' diverse diet helped them survive the Pleistocene mass extinction
Cyber risks can cause disruption on scale of 2008 crisis, study says
Mantis shrimp stronger than airplanes
Greg Bernhardt
Greg Bernhardt is offline
#2
Mar16-04, 10:07 AM
Admin
Greg Bernhardt's Avatar
P: 8,542
What are you trying to compile?
karthik3k
karthik3k is offline
#3
Mar16-04, 10:20 AM
P: 151
Just a simple program to open and read a file.
Declared 2 char pointers in the beginning.
When i changed 1 of them to char array i cud bypass that Error.

dduardo
dduardo is offline
#4
Mar16-04, 11:35 AM
Emeritus
dduardo's Avatar
P: 1,919

Segmentation Fault !!!


Your modifying memory that you shouldn't.

Sometimes this is called a Bus Error
Hurkyl
Hurkyl is offline
#5
Mar16-04, 04:46 PM
Emeritus
Sci Advisor
PF Gold
Hurkyl's Avatar
P: 16,101
In particular, it sounds like you're forgetting to allocate memory.

Recall that the point (haha) of a pointer is that it points to memory. So, unless you have an existing block of memory to which you can tell the pointer to point, the pointer is pointing into nothingness, and a segmentation fault occurs.

Some solutions are:

Declare an array.

Memory does get allocated for arrays, so when you declare one, enough space is allocated to hold the array. So, unless you go out of bounds, you don't have any problem.

Use malloc (or new in C++) to allocate memory, and assign it to the pointer. Don't forget to free (or delete) it when you're done with it!
JohnDubYa
JohnDubYa is offline
#6
Mar25-04, 04:33 AM
P: 1,322
This error often shows up when you call the wrong number of arguments in a function.


Register to reply

Related Discussions
3 Phase System Line to Ground fault Fault current calculation Engineering, Comp Sci, & Technology Homework 1
Networking -Message Segmentation" Engineering, Comp Sci, & Technology Homework 2
Dealing with segmentation faults Programming & Computer Science 5
Ground plane segmentation by Nick Pears General Math 0
San Andreas Fault Earth 5