具有非const变量定义的C++数组

具有非const变量定义的C++数组,c++,C++,我翻阅了一些Android源代码文件,发现函数中声明了以下数组: float a[n][m]; 背景: static bool solveLeastSquares(const float* x, const float* y, const float* w, uint32_t m, uint32_t n, float* outB, float* outDet) { float a[n][m]; // <-------- this array for (u

我翻阅了一些Android源代码文件,发现函数中声明了以下数组:

float a[n][m];
背景:

static bool solveLeastSquares(const float* x, const float* y,
        const float* w, uint32_t m, uint32_t n, float* outB, float* outDet) {

    float a[n][m]; // <-------- this array
    for (uint32_t h = 0; h < m; h++) {
        a[0][h] = w[h];
        for (uint32_t i = 1; i < n; i++) {
            a[i][h] = a[i - 1][h] * x[h];
        }
    }

    // continues...
代码可在第465行找到:

我尝试在VisualStudio中编译,但正如我所预料的,它失败了,因为m和n不能用作常量值


因为这是谷歌Git,是Android的本地框架的一部分,我们知道它可能是有效的,但是有人能解释这是怎么可能的吗?< /P> < P>标准C++不支持可变长度数组,一些编译器——特别是GCC和CLAN-DO支持它们作为C从C99以来支持VLAs的一个转接。但是,微软Visual C++不是编译器之一。

因为某些编译器默认或非标记地启用非标准代码。这能回答你的问题吗?是的,谢谢。从这个问题的答案中,我可以看出这是一个有争议的特点。这个函数是计算Android上ScrollView的滚动速度的过程的一部分,所以我想性能是一个问题。我还是个学生,所以我无法权衡使用这样的非标准代码的利弊。有趣。我不知道这样的特性,这让我对编译器如何处理它感到好奇。我会调查的,谢谢。