I am trying to assign an array of unsigned short depending on a condition. The problem I encounter is the following (according to the code below) :
error C2057: constant expression expected
error C2466: impossible to allocate array with constant size 0
error C2133: 'packet' : unknown size
unsigned int length=4;
if(...)
{
length = 8;
}
else if(...)
{
length = 6;
}
else
{
length = 4;
}
unsigned short packet[length/2];
I tried to do some shenanigans like adding this before the array declaration and using it for the array size but it doesn't do the trick:
const unsigned int halfLength=length/2;
I can't use vectors to replace my array. Do you have any idea ?