访问了非法指针。
The bus in question is the address buss and it contains an illegal value. This is almost always the result of dereferencing a pointer that contains an illegal value.
Here is a program that, I think, will compile with every C or C++ compiler, but should cause a bus error when the second printf is attempted...
Code:
#ifdef __STDC__
#define PROTOTYPICAL
#endif
#ifdef __cplusplus
#define PROTOTYPICAL
#endif
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#ifdef PROTOTYPICAL
int main(int argc, char *argv[])
#else
main(argc,argv)
char *argv[];
#endif
{
double d = 1.23456789;
double *p = &d;
printf ( " d = %f /n" , *p);
p = (double *)((char *)p + 1);
printf ( " d = %f /n" , *p);
exit(0);
}
本文介绍了一个会导致总线错误的C/C++程序示例,该示例通过修改指针使其指向非法内存区域,尝试访问该区域时会触发错误。
2587

被折叠的 条评论
为什么被折叠?



