Segmetation fault

what is this segmentation fault??
Perhaps you should move this the beginner section? A segmentation fault is a memory exception.
Wikipedia wrote:
generally an attempt to access memory that the CPU cannot physically address


http://en.wikipedia.org/wiki/Segmentation_fault
Last edited on
closed account (S6k9GNh0)
Maybe he thought segmentation faults weren't directly related to C++? I don't think they are either actually...
Edited ;)
@ computerquip: That is correct, you can have a Segmetation Fault with any language that allows DMA.

One thing that I don't like about that Wikipedia article is that it doesn't mention that there are different types of SegFaults.

1.) A Local SegFault is when an application writes data to a part of itself that was not intended to hold a variable, or was intended for a different variable there by corrupting that instance of the application running in memory and causing at best undefined behavior. You should be able to cause this on purpose using a dynamically allocated array if you're curious to see what happens, but some compilers\IDE's might try to auto correct the issue.

2.) A Global SegFault is when an application tries to write to a memory address that doesn't exist inside the scope of the application. These are often caught by the Operating System and the offending process is terminated.
A segmentation fault proper will only happen if the process tries to use (both read or write) memory that doesn't belong to it. That's why it's called a segmentation fault; it happens when the process violates segment/page boundaries. It can also happen if the process attempts an operation not allowed by the flags assigned to the page. E.g. attempting to write to read-only memory, or execute non-executable memory.

#1 is more properly a buffer overflow. It can lead to a segfault, depending on what is written and where, but the action by itself is not a segfault.
this error happened when I tried reading the value at address hold by a pointer when the pointer was set to NULL.

this shows that this happens when application try reading a illegal memory location
Last edited on
Topic archived. No new replies allowed.