Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

6
  • What compiler are you using? The array syntax compiles and runs fine with g++ 4.6.4 and 4.7.3. I'm just getting a warning on the last ] before the = that "value computed is not used" or "statement has no effect". However, if I use g++ 4.8.1 (supposedly fully c++11 compliant), it throws errors on n and o not being constant "array size in operator new must be constant", and points to the last ] in the line.
    – jbo5112
    Commented Oct 1, 2013 at 4:59
  • @cmaster double (*in)[m][n] = (double (*)[m][n])new double[k*m*n]; doesn't work too. I'm getting C2057, C2540 errors on n because it isn't known at compile time. I don't understand why I can't do it, because memory allocated properly and it's only pointers to handle this memory conveniently. (VS 2010) Commented Dec 14, 2014 at 11:30
  • 3
    @user3241228 gcc fooled me when I wrote this: supplying -std=c++11 is not enough to switch on strict standard conformance, -pedantic-errors is required as well. Without the later flag, gcc happily accepts the cast, even though it is indeed not according to the C++ standard. With what I know now, I can only advise to fall back to C when doing stuff that's heavily reliant on multidimensional arrays. C99 is just much more powerful in this regard than even C++17 will be. Commented Dec 14, 2014 at 13:46
  • @cmaster dynamically allocated VLAs are syntactic sugar anyway... they're good in C because there's nothing else, but C++ has better syntactic sugar :)
    – M.M
    Commented Sep 30, 2015 at 0:08
  • 3
    @M.M Pity that C++ does not have syntactic sugar for a true, consecutive multidimensional array allocated on the heap with sizes that are only known at runtime. As long as you don't need this, C++ syntactic sugar is fine. But when you need all the above, even FORTRAN beats C++... Commented Sep 30, 2015 at 5:24