Skip to content

Latest commit

 

History

History
41 lines (33 loc) · 1.06 KB

compiler-error-c2057.md

File metadata and controls

41 lines (33 loc) · 1.06 KB
description title ms.date f1_keywords helpviewer_keywords ms.assetid
Learn more about: Compiler Error C2057
Compiler Error C2057
11/04/2016
C2057
C2057
038a99d6-1f5a-42fa-8449-03b4ff11ee0b

Compiler Error C2057

expected constant expression

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

The compiler must know the size of a type at compile time in order to allocate space for an instance of that type.

Examples

The following sample generates C2057 and shows how to fix it:

// C2057.cpp
int i;
int b[i];   // C2057 - value of i is unknown at compile time
int main() {
   const int i = 8;
   int b[i]; // OK - value of i is fixed and known to compiler
}

C has more restrictive rules for constant expressions. The following sample generates C2057 and shows how to fix it:

// C2057b.c
#define ArraySize1 10
int main() {
   const int ArraySize2 = 10;
   int h[ArraySize2];   // C2057 - C does not allow variables here
   int h[ArraySize1];   // OK - uses preprocessor constant
}