☰
  • 首页
  • 规则分类
  • 项目介绍
search
•••

new 运算符第一个数组维度的参数为负数

C++-Undefined-Behavior-38
目录 › next › previous

示例:

int* foo(int n) {
    return new int[n];   // Undefined in C++03 if ‘n’ is negative
}

如果 n 为负数,程序的行为在 C++03 中是未定义的,C++11 去掉了这项未定义行为的声明。

依据

ISO/IEC 14882:2003 5.3.4(6)-undefined
Copyright©2024 360 Security Technology Inc., Licensed under the Apache-2.0 license.