Analitza's use of C99 variable-length arrays

Kevin Krammer krammer at kde.org
Tue Jul 1 08:23:33 UTC 2014


On Tuesday, 2014-07-01, 00:03:08, Nicolás Alvarez wrote:
> 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);

You can also use a QSharedPointer with a custom deleter function.

One thing the vector does provide additional to the allocation/deallocation is 
the initialization, as your exemplatory line shows.

So I guess it depends a bit on whether you want to do that anyway or rather 
not have the overhead.

> I welcome thoughts from someone who actually knows the Analitza code :)

I am not one of those people but I felt like commenting nevertheless ;-)

Cheers,
Kevin
-- 
Kevin Krammer, KDE developer, xdg-utils developer
KDE user support, developer mentoring
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 173 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kde-edu/attachments/20140701/d4732ab0/attachment-0001.sig>


More information about the kde-edu mailing list