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

标签 c c99 object-type

Incomplete TypeObject Type在C语言中的定义是什么?另外,您能否提供一些示例?

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

最佳答案

让我们转到 online C standard (draft n1256) :

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 名称:

struct f *foo;
typedef struct f Ftype;

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

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

关于c - C中不完整类型和对象类型的定义是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3917712/

相关文章:

javascript - Object.prototype.toString.call(null) 什么时候返回[object Object]?

c - 库名和函数名混淆

c++ - 结构位域最大大小(C99,C++)

c - 将队列设计为共享内存

c - 找出sprintf中 "%f"格式的字段长度

C float 0x1.fp3

python - 在第二个脚本函数中传递来自第一个 python 脚本主函数的数据

xml - 如何从 Oracle 数据库中的对象类型生成 XML

c - libubox是否支持多线程

c - sscanf 转换为长整型