的定义是什么不完整型 and 对象类型在C语言中?另外,您能否提供一些例子?
ANSI C99 在不同的地方提到了这两种类型类别,尽管我发现很难理解它们的确切含义(没有段落/句子明确定义它们是什么)。
让我们去在线 C 标准(草案 n1256) http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1256.pdf:
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).
示例不完整的 types:
struct f; // introduces struct f tag, but no struct definition
int a[]; // introduces a as an array but with no defined size
您无法创建不完整类型的实例,但您可以can从不完整类型创建指针和 typedef 名称:
struct f *foo;
typedef struct f Ftype;
要将不完整的结构体类型转换为对象类型,我们必须定义该结构体:
struct f
{
int x;
char *y;
};
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)