Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22040

Initialized Variable Length Array Working Variably (Between Computers)

$
0
0

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?


Viewing all articles
Browse latest Browse all 22040

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>