可变长度的结构体定义

 1 /**
 2 ***************************************************************************************** 
 3 *    @FileName        可变长度的结构体成员 
 4 *    @Editor          一点零一 
 5 *    @EdotTime        2017年12月27日 
 6 *    @Version         V0.1 
 7 *    @Note
 8 *****************************************************************************************
 9 */
10  
11 #include<stdio.h>
12 #include<stdlib.h>
13 
14 
15 typedef struct
16 {      
17     unsigned char ch;
18     int *data;  
19 }VLEN_s;
20  
21 int main()
22 {
23     char i;
24     VLEN_s s_Obj;
25     int str[10];
26       
27 #if 0
28     /* 动态内存分配空间 */
29     s_Obj.data = (int *)malloc(sizeof(int)*10);
30 #else
31     /* 使用定义数组 */ 
32     s_Obj.data = str;
33 #endif
34       
35     s_Obj.data[0]=1;
36     s_Obj.data[1]=5;
37     
38     for(i = 0; i < 10; i++)
39          printf("%d
", s_Obj.data[i]);
40     return 0;
41 }
原文地址:https://www.cnblogs.com/skullboyer/p/8126476.html