不完整类型Incomplete Types

不完整类型是一种用于描述标识符但缺少确定该标识符的大小所需的信息的类型。An incomplete type is a type that describes an identifier but lacks information needed to determine the size of the identifier. “不完整类型”可以是:An "incomplete type" can be:

  • 您尚未指定其成员的结构类型。A structure type whose members you have not yet specified.

  • 您尚未指定其成员的联合类型。A union type whose members you have not yet specified.

  • 您尚未指定其维度的数组类型。An array type whose dimension you have not yet specified.

    void 类型是无法完成的不完整类型。The void type is an incomplete type that cannot be completed. 若要完成不完整类型,请指定缺少的信息。To complete an incomplete type, specify the missing information. 以下示例演示如何创建和完成不完整类型。The following examples show how to create and complete the incomplete types.

  • 若要创建不完整的结构类型,请声明结构类型而不指定其成员。To create an incomplete structure type, declare a structure type without specifying its members. 在本例中,ps 指针指向称为 student 的不完整的结构类型。In this example, the ps pointer points to an incomplete structure type called student.

    struct student *ps;  
    
  • 若要完成不完整的结构类型,请在稍后在指定其成员的同一范围中声明相同的结构类型,如下所示:To complete an incomplete structure type, declare the same structure type later in the same scope with its members specified, as in

    struct student  
    {  
        int num;  
    }                   /* student structure now completed */  
    
  • 若要创建不完整的数组类型,请声明数组类型而不指定其重复计数。To create an incomplete array type, declare an array type without specifying its repetition count. 例如:For example:

    char a[];  /* a has incomplete type */  
    
  • 若要完成不完整的数组类型,请在稍后在指定其重复计数的同一范围中声明相同的名称,如下所示:To complete an incomplete array type, declare the same name later in the same scope with its repetition count specified, as in

    char a[25]; /* a now has complete type */  
    

另请参阅See Also

声明和类型Declarations and Types