GNU C中的零长度数组
来源:互联网 发布:什么是单例模式 java 编辑:程序博客网 时间:2024/04/25 10:01
GNU C对标准C进行了一系列的扩充,其中零长度数据就是GNU C所特有的
如下结构体:
typedef struct _data_struct
{
int length;
char data[0];
}data_struct;
就是一个零长度数组,这个结构体并没有为数组data分配空间,此结构体的大小sizeof(data_struct)==sizeof(length)。
我们在使用时可以根据需要创建数组的大小:
int my_data_length = 10;
data_struct *datap = (data_struct *)malloc(sizeof(data_struct) + sizeof(char)*my_data_length);
datap->length = my_data_length;
for(int i = 0; i < datap.length; i++)
{
strcpy(datap.data[i], i);
.......
}
free(datap);
好处是可以动态的申请数组的大小,这在网络编程中会有用到,先记下来
- GNU C中的零长度数组
- GNU C中的零长度数组
- GNU C中的零长度数组
- GNU C中的零长度数组
- GNU C中的零长度数组
- GNU C中的零长度数组
- GNU C中的零长度数组
- GNU C中的零长度数组
- GNU C中的零长度数组
- GNU C中的零长度数组
- GNU/C 零长度数组
- GNU C中的零长度/变长数组 、内存空间节省
- GNU C中的零长度数组(应用于伙伴系统算法)
- C语言中的零长度数组使用说明
- C 零长度数组
- GNU C语言的 扩展(二)零长度数组&可变参数宏
- C语言零长度数组
- GNU C中的数组类型
- 【B-Human】之Module与Representation
- C++实现快排算法
- 2012年4月7日腾讯实习生笔试中的一道数据库题目
- OOP中一些概念理解
- Failed to create the Java Virtual Machine
- GNU C中的零长度数组
- 扩容U盘修复
- typedef使用总结
- D3D D2D DWrite
- strtok和strtok_r
- 在eclipse-php中添加svn插件
- UVa 409 - Excuses, Excuses!
- Android 相片管理专题之拍照功能
- How To Install Ubuntu 12.04 from USB Drive