Compiler Error C2057

expected constant expression

The context requires a constant expression, an expression whose value is known at compile time.

Example

The following sample generates C2057:

// C2057.cpp
int i;
int b[i];   // C2057
int main() {
   const int i = 8;
   int b[i];
}

C has more restrictive rules for constant expressions. The following sample generates C2057:

// C2057b.c
#define ArraySize1 10
int main() { 
   const int ArraySize2 = 10; 
   int h[ArraySize2];   // C2057
   int h[ArraySize1];   // OK
}