In C, is there any way to initialize a struct member struct with a variable, or must I initialize with another initialize list? I realize the wording of these questions is terribly confusing, so here's a trivialized code example
#define MAX_VECTOR_SIZE 10 struct ImmutableVectorC { const short vectorSize; int vectorElements[MAX_VECTOR_SIZE]; }; struct ImportantVectors { struct ImmutableVectorC vec1; struct ImmutableVectorC vec2; struct ImmutableVectorC vec3; struct ImmutableVectorC vec4; struct ImmutableVectorC vec5; } Suppose I have these structs defined. I want to initialize an ImportantVectors struct with another struct. Is it possible to do something along these lines?
int main() { struct ImmutableVectorC tempStruct = { .vectorSize = (short)2, .vectorElements = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }; struct ImportantVectors initial = { .vec1 = tempStruct, .vec2 = tempStruct, .vec3 = tempStruct, .vec4 = tempStruct, .vec5 = tempStruct }; } Visual studio is giving cryptic errors and I'm not sure it it's because these aren't compile-time constants, or some memory management issues, etc.
edit: The error VS gives me is:
error C2440: 'initializing' : cannot convert from 'struct ImmutableVectorC' to 'const short'