我试图使一个Python程序接口与不同的崩溃进程(这是我的手)。不幸的是,我正在使用的程序甚至不会可靠地崩溃!所以我想做一个快速的c++程序,它会故意崩溃,但我不知道最好和最短的方法来做到这一点,有人知道在我的

int main() {
    crashyCodeGoesHere();
}

使我的c++程序可靠地崩溃


当前回答

*((unsigned int*)0) = 0xDEAD;

其他回答

这是Breakpad中谷歌提供的代码片段。

  volatile int* a = reinterpret_cast<volatile int*>(NULL);
  *a = 1;

我唯一的闪光是abort()函数:

它以异常的程序终止终止进程。它生成SIGABRT信号,默认情况下,该信号导致程序终止,并向主机环境返回一个不成功的终止错误代码。程序终止时不执行自动或静态存储持续时间对象的析构函数,也不调用任何atexit(在程序终止前由exit()调用)函数。它从不返回调用者。

死循环递归方法调用导致堆栈溢出怎么办?

#include <windows.h>
#include <stdio.h>

void main()
{
    StackOverflow(0);
}

void StackOverflow(int depth)
{
    char blockdata[10000];
    printf("Overflow: %d\n", depth);
    StackOverflow(depth+1);
}

请参阅Microsoft KB上的原始示例

*( ( char* ) NULL ) = 0;

这将产生一个分割错误。

Try:

raise(SIGSEGV);  // simulates a standard crash when access invalid memory
                 // ie anything that can go wrong with pointers.

中发现:

#include <signal.h>