简体   繁体   English

结构内部的struct数组

[英]Array of struct inside of a struct

why can't i do this: 为什么我不能这样做:

 typedef struct _word{
      struct _word ws[ 28 ];
 }Word;

With the code above i'm get the error: field 'ws' has incomplete type. 使用上面的代码我得到错误:字段'ws'具有不完整的类型。

Why can i do just this: 我为什么这样做:

 typedef struct _word{
      struct _word *wr[ 28 ];
 }Word;

I want static memory. 我想要静态内存。

Because if your structure is not completely defined, you can't calculate the size of the object to be allocated. 因为如果您的结构未完全定义,则无法计算要分配的对象的大小。 As others mentioned, it'll be an infinite regression trying to deduce the size of the object. 正如其他人所提到的那样,试图推断出对象的大小是无限的回归。

But you can always calculate the size of a pointer. 但是你总是可以计算指针的大小。 Hence the 2nd version works. 因此第二个版本有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM