typedef和结构体的定义之间的道道

来源:互联网 发布:星际争霸空投闪电矩阵 编辑:程序博客网 时间:2024/04/28 18:58
typedef struct struct_1 struct_1_t;       /*struct_1_t is a type name represent struct struct_1 */                                           struct struct_1 {                         /*struct_1 is only name of struct*/<span style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace;"></span><span style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace;">                 </span><span style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace;">   </span><pre name="code" class="cpp">    int i;<span style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace;">                                                                    </span>
};  /*if you want to name another same struct ,we have to write like this"struct struct_1 example1"*/                                                                                                                                                                      typedef struct struct_2 {        /*It is simalar with first writing style,it's a type definition.*/                                                        int i;                                                                           } struct_2_t;                                                                                                                                                             typedef struct {                                                                         int i;                                                                           } struct_3_t;    /*this is definition type for a struct ,struct_2_t is type name of struct*/                                                                                                                                                         struct {                                                                                 int i;                                                                           } struct_var_4;    
                                                          //this is basic definition,when we first to access to struct,don't you remember
<pre name="code" class="cpp">struct struct_5{ int i; } struct_var_5; //of course,two position can really ha//ve same name,because of their different meaning //the first "same_name" is just struct'//s name,the second is one of declara//tion like struct same_name example//1 struct same_name { int i; } same_name; typedef struct same_name2 { int i; } same_name2;


                                             
0 0
原创粉丝点击