C中不完整类型和对象类型的定义是什么? [英] What is the definition of Incomplete Type and Object Type in C?

查看:60
本文介绍了C中不完整类型和对象类型的定义是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C中不完整类型对象类型的定义是什么?另外,您能提供每个示例的例子吗?

What is the definition of Incomplete Type and Object Type in C? Also, could you provide some examples of each?

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

ANSI C99 mentions both type categories in various places, though I've found it difficult to understand what each of them means exactly (there is no paragraph/sentence explicitly defining what they are).

推荐答案

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


6.2.5类型


1存储在对象中或由函数返回的值的含义取决于用于访问它的表达式的
类型。 (声明为对象的标识符是最简单的这样的表达式;在标识符的声明中指定了类型。)类型分为对象类型(完全描述对象的类型),函数类型(描述函数的类型)和不完整类型(描述对象但缺少确定其大小所需的信息的类型)。
6.2.5 Types

1 The meaning of a value stored in an object or returned by a function is determined by the type of the expression used to access it. (An identifier declared to be an object is the simplest such expression; the type is specified in the declaration of the identifier.) Types are partitioned into object types (types that fully describe objects), function types (types that describe functions), and incomplete types (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名称:

You cannot create instances of incomplete types, but you can create pointers and typedef names from incomplete types:

struct f *foo;
typedef struct f Ftype;

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

To turn the incomplete struct type into an object type, we have to define the struct:

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

这篇关于C中不完整类型和对象类型的定义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆