我有一个这样的结构:
typedef struct tree_s{
    struct tree_s *a;
    int b;
}tree_t;
目前,我正在以这种方式进行初始化:
tree_t branch_n = {
    .a = NULL,
    .b = 2
};
tree_t root = {
    .a = (tree_t*) &branch_n, 
    .b = 1
};
现在,让我很恼火的是,我必须在根之前初始化较低的分支,因为完整的结构非常大,分支有自己的分支,使我的代码难以管理。
我想做的是这样的:
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
};
我怎样才能实现这样的初始化?
我想这样做的主要原因是大大增强我的代码的概述,并立即直观地看到“树”的结构。
请注意,从一开始就知道完整“树”的结构,这就是我认为结构不变的原因。但是值 b 可以随时更改。
我对 C 语言很陌生,这是我在 SO 上的第一篇文章,所以请随时编辑或询问我是否无法让自己清楚:)