Different behavior of compilers with array allocation

后端 未结 3 1658
旧时难觅i
旧时难觅i 2021-01-18 07:37

I recently found a interesting behaviour of g++ when compared with MSVC++ 2008. Consider this tiny program:

#include 

const int ARR_LENGTH =          


        
相关标签:
3条回答
  • 2021-01-18 08:24

    Dynamically sized arrays are a feature of C99. If your compiler supports C99 (GCC does, VC doesn't fully) - and if you throw the C99 switch -, then this will compile.

    0 讨论(0)
  • 2021-01-18 08:28

    C99 (the most recent version of the C standard) does allow dynamically sized arrays. However, the feature is not supported by Visual Studio (which only implements C89 support)

    In C++ it is not, and probably will never be, valid.

    0 讨论(0)
  • 2021-01-18 08:32

    This is not standard C++ (but standard C). Implementations may provide alloca (or _alloca with msvc) which pretty much does the job.

    0 讨论(0)
提交回复
热议问题