The thing is that I might want to populate the arrays with more fields at a later stage so then I don't want to specify the amount of fields available in the array. Any suggestions for me?
The behaviour is a feature/limit of C / C++ compilers; certainly all the ones I have used. The compiler is telling you it is not prepared to do all the work for you. In this case, calculating the size of the array and then the size of the structure and then initialising the array, would take a pass of the compiler too many.
There are many different ways around the limitation. Some are safer than others, some more efficient then others, some easier to maintain than others. For instance, you might put the length of the array in a variable or the entirety of the data in a macro.
Personally, for a fixed length array, I would go with what you already have, with the length of the array declared next to the initialiser making it easier to debug. However, if you need to start passing the array to functions, a variable becomes easier to maintain.
If what you are really after is a dynamically sized array, the answer is a bit more complicated.
I might want to populate the arrays with more fields at a later stage so then I don't want to specify the amount of fields available in the array
If you were able to increase the size of the array at a later stage then you would need the memory to be available to do it at that time so you might just as well declare the array at its maximum size to begin with.
Whilst I appreciate that your example is only that and not real code (or is it ?) why are the values in the array declared as ints rather than bytes if your aim is to save space ?
Thanks for all the replies and my apologies for the late reply. Thank you for the explanation as well. I will make use of a variable to size the arrays as suggested then. Much appreciated.
UKHeliBob:
If you were able to increase the size of the array at a later stage then you would need the memory to be available to do it at that time so you might just as well declare the array at its maximum size to begin with.
One way, and I would recommend using C++ classes for this, would be to make objects that hold the array data with links or indexes in RAM to other objects. Newly allocated objects can link in with the others, even do sorted order.
There is an Arduino bootloader that allows sketches to write to flash, potentially wiping your sketch out if you get the address wrong. You can store constant data known at compile time in flash using PROGMEM to save using RAM. That bootloader allows writing to flash at run time.
OP, a struct is a definition of data by compiler name, data type and address relative to the struct base address. It’s a template of a data type. You can make a pointer to your type struct and pointers to other structs and use one common buffer… like the default 512 byte SD buffer that gets SD reads and does SD writes.
You can write what is in the buffer to SD and you can read from SD to the buffer, changing the arrays.
You can log your data by writing the buffer occasionally, put in debug data instead of printing to serial monitor.
Look into SD and Arduino, You can make your own if you can solder or get a cheap module if not.