I am assigning a 3D array via an initializer list to a struct, to take advantage of member-wise copy. I was interested in doing something like what was described in this post about array copying
This seems to work, but it can't be done without adding an extra set of brackets:
struct Options
{
char array [20][20][20];
};
int main(void)
{
Options K = {{ { "-x", "-o" }, { "-y", "-p", "-q" }, {"-r", "-s"} }};
};
The outermost brackets are to encapsulate the value being assigned. The next pair in is the extra pair I can't explain. The 3 dimensions to be assigned are:
- x = number of bracketed groups of strings
- y = number of strings in each group
- z = number of characters in each string
This would normally not worry me because everything is copied. However, after assignment, innermost values that should be contiguous in memory are spaced apart by multiples of an extra dimension. Instead of "-x" and "-o" being separated by 20 bytes, for example, they are actually separated by 20 * 20 bytes. I'm confused. How do I get this to work without adding an extra dimension?