I need something like this:
Code:
#define x 5;
struct A{
int array[x];
};
void main(void){
struct A a = {0};
for (int i = 0; i < x; ++i)
{
a.array[i] = rand();
}
}
But it's complaining:
line 1: error: expected ']' before ';' token
line 10: error: expected expression before ';' token
How do I make it work? I thought that macros were just like find/replace instructions for the compiler... Apparently not? I'm using gcc 9.3.0 targeting x86-64
I'd rather not use something like
Code:
struct A{
int* array;
}
because then the array's position in memory is not necessarily anywhere near the position of the struct. Apart from having to manually allocate the array's memory.