J
Josh Lessard
Given a union definition:
union problem_t {
int mask[2];
struct {
int indices[2];
int ops[2];
} comp;
};
Is it possible to initialize the struct containing the two arrays when
declaring a variable of this type? I've tried just about every
combination I can think of, but I can't seem to get it to work. For
example:
int main() {
problem_t problem = { {}, { { 0, 0 }, { 0, 0 } } };
}
union.cc: In function `int main()':
union.cc:12: excess elements in aggregate initializer
I've tried omitting the empty array representing the first element of the
union and that doesn't work either. I can't simply reverse the two union
elements, because I initialize it differently in different parts of my
program depending on how I want the union used.
Any ideas? Thanks in advance...
union problem_t {
int mask[2];
struct {
int indices[2];
int ops[2];
} comp;
};
Is it possible to initialize the struct containing the two arrays when
declaring a variable of this type? I've tried just about every
combination I can think of, but I can't seem to get it to work. For
example:
int main() {
problem_t problem = { {}, { { 0, 0 }, { 0, 0 } } };
}
union.cc: In function `int main()':
union.cc:12: excess elements in aggregate initializer
I've tried omitting the empty array representing the first element of the
union and that doesn't work either. I can't simply reverse the two union
elements, because I initialize it differently in different parts of my
program depending on how I want the union used.
Any ideas? Thanks in advance...