I was digging through some of Android source code files and found this array declared inside a function:
float a[n][m];
The context:
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...
The code can be found here (line 465): https://android.googlesource.com/platform/frameworks/native/+/refs/heads/master/libs/input/VelocityTracker.cpp
I tried to compile in Visual Studio, but, as I expected, it failed because m
and n
cannot be used as constant values.
Since this is from Google Git and is part of Android's native framework, we know it (probably) works, but can anyone explain how this is possible?