This is my code:
int main() { const int LEN = 5; int x[LEN]; }
VS10 says:
Error C2057: Expected Constant Expressionerror C2466: cannot allocate array of constant size 0error C2133: 'x': unknown size
Error C2057: Expected Constant Expression
error C2466: cannot allocate array of constant size 0
error C2133: 'x': unknown size
I even tried the code on this page and it gives the same problem (I commented on the code that gives the error and uncommented the correct one): http://msdn.microsoft.com/en-us/library/eff825eh%28VS.71% 29.aspx
If I tried to use the crappy compiler, I would think that this is a bug in the compiler, but this is VS2010!
, , .c. MS Visual C C99. C89 . const C. , .
const
AndreyT.
.cpp.
http://msdn.microsoft.com/en-us/library/3ffb821x.aspx, ", const, ", , ++.
, , - , - #define. sje397, , LEN ? , , # ?
LEN
: , , ++, , C, .
int main() { enum { LEN = 5 }; int x[LEN]; }
:
int main() { const int LEN = 5; int* LENptr = (int*)(&LEN); *LENptr = 10; int x[LEN]; }
const ,
Source: https://habr.com/ru/post/1780608/More articles:STL std :: map dynamic ordering - c ++UDP SO_TIMESTAMP in windows - windowsHow the std :: cout / object is created - c ++Admob orientation support for Android - androidFilter data in ListView [mvvm] - c #Adding annotation syntax to a C ++ source - c ++General question with the question of returning to C # - c #Java-like annotations in C ++ - javaНе удается запустить powerpoint из ярлыка меню запуска в С# - c#Does Android cursor look at all database paths? - androidAll Articles