linux c 结构中定义结构

来源:互联网 发布:淘宝查快递怎么查询 编辑:程序博客网 时间:2024/04/20 12:55
  1. #include "stdio.h"  
  2.   
  3. typedef struct  BB   
  4. {    
  5.      union AA  //没有typedef  
  6.     {    
  7.         int t;   //4    
  8.         short m; //2    
  9.         char p;  //1    
  10.     } AA;  
  11.  struct C //没有typedef
  12.    {
  13.       int t; //4
  14.    }C;
  15.     double c;    //8    
  16.     char p2;     //1    
  17. }BB;   
  18.   
  19.   typedef union  A //有typedef  
  20.     {    
  21.         int t;   //4    
  22.         short m; //2    
  23.         char p;  //1    
  24.     }A;    
  25.             
  26.  typedef   struct   B    
  27.     {    
  28.         A a;          //4    
  29.         double c;    //8    
  30.         char p2;     //1    
  31.     }B;    
  32.       
  33.       
  34.   int main()  
  35.   {  
  36.       printf("BB:%d\n",sizeof(BB));  
  37.       printf("B:%d\n",sizeof(B));  
  38.       return 0;  
  39.   } 
0 0
原创粉丝点击