I have some code that initializes arrays, specifically C-strings, using variables. For example...
int len = getLength();char cstr[len+1] = {'\0'};
This compiles and runs flawlessly in my code. However, when one of my co-workers runs the same code, he gets the compiler error...
Variable-sized object may not be initialized
We're both using Ubuntu and GCC/G++. We've compared compiler flags, and we're both using --std=c++11
. All the rest of the flags are also the same (-Wall
, -Wextra
and -g
).
Why is this code only working on my computer, and not his? How can I get it working?