When I initialize a single element into a void structure, it works fine:
void* CMD_ARRAY[] =
{
{"+++\r"},
{"+++\r"},
{"+++\r"},
};
However, when I try to add more elements to the structure, i.e.:
void* CMD_ARRAY[] =
{
{"+++\r" , 4, 1300},
{"+++\r" , 4, 1300},
{"+++\r" , 4, 1300},
};
This results in an error:
expected a “}”
What is the difference between a single element as in the 1st example, and a structure of a structures (which are also considered as elements)?
How can I achieve initialization of this void structure with mixed types?
Update:
So I understand that the compiler doesn’t know how to handle different types in the same elements. Is there a way to define these types on the fly (i.e. using casting) without actually defining the structure outside this definition (i.e. using an array of strucutres)?
I would suggest that the compiler can’t guess certain details regarding your implicit struct declarations. For example, how is your compiler to guess that I wanted
yin the example below to be ashort?This could be expanded at the cost of legibility to:
edit: In addition to the cost of legibility, consider what will happen if you decide to change your struct at the higher level. You’ll have to do plenty of finding/replacing in the lower level. Does this sound sweet to you?