user745759
user745759

Reputation: 9

error C2057 with HANDLE

I try to compile flushmem.cpp with ms visual c++ 2008, but obtain error: .\flushmem.cpp(69) : error C2057: expected constant expression at line: HANDLE processes[processCount]; and a warning: .\flushmem.cpp(63) : warning C4244: 'initializing' : conversion from 'unsigned __int64' to 'unsigned int', possible loss of data at line: unsigned processCount = (totalPageFile + approximateProcessConsumption - 1) / approximateProcessConsumption;

how to solve?

Upvotes: 0

Views: 127

Answers (1)

Jim Rhodes
Jim Rhodes

Reputation: 5085

The Visual Studio 2008 compiler does not support a variable as the size of an automatic array. In the line:

 HANDLE processes[processCount];

processCount is a variable and the compiler will only accept a constant. You will need a C99 compliant compiler or you need to change the above line of code to allocate the array. For instance:

HANDLE* processes = new HANDLE[processCount];

If you allocate the array you will also need to delete it when you are done with it:

delete [] processes;

Upvotes: 1

Related Questions