I've been trying to solve this problem for hours now. Although I found some similar questions, it just won't work. I have a union within a struct. Now I want to initialize a const variable of this struct.
struct length
{
int minutes;
int seconds;
};
typedef struct article
{
char name[MAXLENGTH_A]
double price;
char type;
union size
{
int pages;
struct length blength;
} bsize
} art;
Now I want to initialize a const variable of this struct. I read somewhere that the following should work, but it doesn't. I always get the errors: C2224: The operand to the left of '.pages' is not a class, structure, or union and C2078: To many Initializers
const art book = {"Title", 24.99, NORMAL, { .pages = 50}};
I know that this example could be solved easier. But my real problem is, to initialize the 2nd element of the union, like this:
const art book = {"Title", 24.99, AUDIO, { .blength.seconds = 40}};
Neither the first, nor the second initialization is working. Can someone tell me how do it right? I'm using C99 btw.