Analitza's use of C99 variable-length arrays
Nicolás Alvarez
nicolas.alvarez at gmail.com
Tue Jul 1 03:03:08 UTC 2014
Hi peeps,
In analitza/commands/blockmatrixcommands.cpp, there is a variable-length array:
const int firstVectorSize = firstVector->size();
int blockpattern[firstVectorSize];
This is a new feature in C99. The GCC manual says: "Variable-length
automatic arrays are allowed in ISO C99, and as an extension GCC
accepts them in C90 mode and in C++."
MSVC doesn't support VLAs, at least not in C++ mode. And given the
above quote, it seems it's non-portable to use it in C++ anyway, so
(this time :P) we can't blame it on MSVC not being standards-compliant
or something.
I replaced it with this to make it compile:
std::unique_ptr<int[]> blockpattern(new int[firstVectorSize]);
But I don't know if this is acceptable (can I use C++11 in analitza?).
##c++ told me to just use
std::vector<int> blockpattern(firstVectorSize, 0);
which is a reasonable option, but it feels weird to use a std::vector
for something that won't be resized.
I welcome thoughts from someone who actually knows the Analitza code :)
--
Nicolás
More information about the kde-edu
mailing list