I'm having a struct like this:
typedef struct tree_s{
struct tree_s *a;
int b;
}tree_t;
Which, at the moment, I am initializing in this way:
tree_t branch_n = {
.a = NULL,
.b = 2
};
tree_t root = {
.a = (tree_t*) &branch_n,
.b = 1
};
Now, it annoys me that I have to initialize the lower branches before the root because the complete structure is quite large, with the branches having branches on their own, making my code hard to manage.
What I would like to do is something like this:
tree_t root = {
.a =
//The first branch
{
.a =
//Yet another branch
{ //Since the following is actually an array, I need the
// "a" above to point to the first index
{
.a = NULL, //Maybe this will have its own branch
.b = 3
},
{
.a =
{
.a = NULL, //And this might even have its own branch
.b = 5
}
.b = 4
}
}
.b = 2
},
.b = 1
};
How can I achieve an initialization like this?
The main reason I want to do this is to greatly enhance the overview of my code and immediately visually see the structure of the "Tree".
Note that the structure of the complete "Tree" is know from the start which is why I consider the structure constant. The value b however may be changed at any time.
I am quite new to the C language and this is my first post on SO, so feel free to edit or ask if I havent been able to make myself clear :)