gpt4 book ai didi

g++ - 是否可以在 g++ 中启用数组边界检查?

转载 作者:IT老高 更新时间:2023-10-28 22:28:30 27 4
gpt4 key购买 nike

在编译带有一些标志的以下文件时,是否可以让 g++ 显示错误?

#include <iostream>
using namespace std;

int main()
{
int arr[ 2 ];

cout << arr[ 4 ] << endl;

return 0;
}

我看到了像 gcc -Wall -O2 main.c 这样的东西,它只适用于 C,而不适用于 C++。

最佳答案

不是在编译时。不过,您也许可以在运行时检查。

为此,请查看: Runtime array bounds checking with g++

关于g++ - 是否可以在 g++ 中启用数组边界检查?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4778552/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com