大佬教程收集整理的这篇文章主要介绍了一个结构体中未定义的数组声明,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
所以如果你有一个s *,那么除了结构体所需的空间之外,你还可以为数组分配空间,通常你会在结构中有其他成员:
s *s1 = malloc( sizeof(struct s) + n*sizeof(int) ) ;
该标准草案在第17段中实际上有一个指导性的例子:
EXAMPLE After the declaration: struct s { int n; double d[]; }; the structure struct s has a flexible array member d. A typical way to use this is: int m = /* some value */; struct s *p = malloc(sizeof (struct s) + sizeof (double [m])); and assuming that the call to malloc succeeds,the object pointed to by p behaves,for most purposes,as if p had been declared as: struct { int n; double d[m]; } *p; (there are circumstances in which this equivalence is broken; in particular,the offsets of member d might not be the samE).
以上是大佬教程为你收集整理的一个结构体中未定义的数组声明全部内容,希望文章能够帮你解决一个结构体中未定义的数组声明所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。