I'm actually working on an assignement in C, and for the need of my implementation, I need to use a static array, let's say
static int array[LEN];
The trick is that this array length, LEN, is computed in the main(). For example
static int LEN;
void initLen(int len) {
LEN = len;
}
static int array[LEN];
Where initLen is called in the main, and len is computed using the arguments given by the user.
The issue with this design, is that I get the error
threadpool.c:84: error: variably modified ‘isdone’ at file scope
The error is due to the fact that we cannot initialize static arrays using variables as length. To make it work, I'm defining a LEN_MAX and write
#define LEN_MAX 2400
static int array[LEN_MAX]
The issue with this design is that i'm exposing myself for buffers overflows and segfaults :(
So I'm wondering if there is some elegant way to initialize a static array with the exact length LEN?
Thank you in advance!
isdoneand what does it have to do with your array? Nowhere in your question, except the error message, is thisisdonevariable mentioned. Please provide a SSCCE instead.isdoneis just the real array in my program, array that I simply calledarrayin my example.