Incomplete Type和Object 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/