本文介绍了是否可以在g ++中启用数组边界检查?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在使用某些标志编译以下文件时,g ++是否可能显示错误?
Is it possible to have g++ show an error when compiling the following file with some flag?
#include <iostream>
using namespace std;
int main()
{
int arr[ 2 ];
cout << arr[ 4 ] << endl;
return 0;
}
我看到了一些东西,例如 gcc -Wall -O2
I saw some things like gcc -Wall -O2 main.c
which only works with C, not C++.
推荐答案
不是在编译时。您可以在运行时检查它。
Not at compile time. You might be able to check that at runtime though.
有关详情,请参阅:
For that take a look at:Runtime array bounds checking with g++
这篇关于是否可以在g ++中启用数组边界检查?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!