Today a little argument erupted over the following code line in a fairly time critical piece of C++ that was running.
void func(std::string& str)
{
...
uint8_t buffer[str.size() + 10];
...
}
Now obviously you can compile this in C as the standard supports dynamically sized arrays. However GCC C++ seems to allow this kind of construct through some kind of an extension. MSVC doesn't allow this kind of statement, so we were a bit puzzled.
Does GCC allocate it at declaration time and is this allocation done on the stack? Is it syntactic sugar for a dynamic allocation, like say using new to create an array?
Is there are performance penalty for using a dynamically sized array over say a static one, given that a static one would be allocated in the prologue?