(. Segmentation fault segfault) , . Motorola 68000 , , .
UNIX- , , SIGSEGV. Microsoft Windows, , , STATUS_ACCESS_VIOLATION, , , Dr. Watson, Microsoft.
[]
ANSI C, :
const char *s = "hello world"; *(char *)s = 'H';
, , , «hello world» « ». , . s , H .
OpenBSD 4.0 :
$ gcc segfault.c -g -o segfault
$ ./segfault
Segmentation fault
gdb:
Program received signal SIGSEGV, Segmentation fault.
0x1c0005c2 in main () at segfault.c:6
6 *s = 'H';
$ gcc segfault.c -g -o segfault
segfault.c: In function main:
segfault.c:4: error: assignment of read-only location
, , .
int* ptr = (int*)0; *ptr = 1;
int main() { main(); }
, : , (, ), .
,
char* p1 = NULL; /* , , */
char* p2; /* */
char* p3 = (char *)malloc(20); /* , */
free(p3); /* */
.
, , . :
int main() { int const nmax=10; int i,n,a[n]; }
| . |
g++ , .
[] .
[]
- http://www.faqs.org/qa/qa-673.html (.)
- http://c-faq.com/null/null1.html (.)
- http://c-faq.com/null/varieties.html (.)
| () | |
|---|---|

