繁体   English   中英

C中不完全类型和对象类型的定义是什么?

[英]What is the definition of Incomplete Type and Object Type in C?

C中不完全类型对象类型的定义是什么? 另外,你能提供一些例子吗?

ANSI C99在不同的地方提到了两种类型,尽管我发现很难理解它们各自的含义(没有明确定义它们的段落/句子)。

让我们转到在线C标准(草案n1256)

6.2.5类型

of the expression used to access it. 1存储在对象中或由函数返回的值的含义由用于访问它的表达式的决定。 (types that fully describe objects), (types that describe functions), and (types that describe objects but lack information needed to determine their sizes). (声明为对象的标识符是最简单的表达式;类型在标识符的声明中指定。)类型被分区为 (完全描述对象的 ), (描述函数的类型),以及 (描述对象的类型,但缺少确定其大小所需的信息)。

不完整类型的示例:

struct f;    // introduces struct f tag, but no struct definition
int a[];     // introduces a as an array but with no defined size

您不能创建不完整类型的实例,但您可以从不完整类型创建指针和typedef名称:

struct f *foo;
typedef struct f Ftype;

要将不完整的结构类型转换为对象类型,我们必须定义结构:

struct f
{
  int x;
  char *y;
};

我所知道的类型是:

  • 不完整的类型
  • 对象类型
  • 功能类型

这是一个例子(也在键盘上: http//codepad.org/bzovTRmz

#include <stddef.h>

int main(void) {
    int i;
    struct incomplete *p1;
    int *p2;
    int (*p3)(void);

    p1 = NULL; /* p1 is a pointer to a incomplete type */
    p2 = &i;   /* p2 is a pointer to an object */
    p3 = main; /* p3 is a pointer to a function */

    return 0;
}

struct incomplete可以在另一个翻译单元中定义(具有确定的大小)。 这个翻译单元只需要指针

暂无
暂无

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

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