Non-const declaration of array

后端 未结 8 882
你的背包
你的背包 2020-12-19 05:11

I have been teaching myself programming for couple of years, and I was sure that if you need array declaration of a variable number you need to use malloc or

8条回答
  •  借酒劲吻你
    2020-12-19 05:31

    There is an extension of GCC mimicking C99 Variable Length Arrays. It's not standard C++.

    However, even if you have this turned off, the posted code can compile. The standard does not require a diagnostic for this case: it's Undefined Behaviour, not an error.

    In really obvious cases a compiler may choose to prevent you from writing this, but otherwise it is free to let you fail in peace.

    Conclusion: don't be fooled by the compilation. It's still bad and wrong.

提交回复
热议问题