另外:前向声明中引入的类型为不完全类型(incomplete type),不完全类型只能以有限方式使用,只能用于定义指向该对象的指针和引用,只能用于声明使用该类型作为形参或返回类型的函数。

Incomplete types[edit]

An incomplete type is a structure or union type whose members have not yet been specified, an array type whose dimension has not yet been specified, or the void type (the void type cannot be completed). Such a type may not be instantiated (its size is not known), nor may its members be accessed (they, too, are unknown); however, the derived pointer type may be used (but not dereferenced).

They are often used with pointers, either as forward or external declarations. For instance, code could declare an incomplete type like this:

struct thing *pt;

This declares pt as a pointer to struct thing and the incomplete type struct thing. Pointers to data always have the same byte-width regardless of what they point to, so this statement is valid by itself (as long as pt is not dereferenced). The incomplete type can be completed later in the same scope by redeclaring it:

struct thing {
int num;
}; /* thing struct type is now completed */

Incomplete types are used to implement recursive structures; the body of the type declaration may be deferred to later in the translation unit:

typedef struct Bert Bert;
typedef struct Wilma Wilma; struct Bert {
Wilma *wilma;
}; struct Wilma {
Bert *bert;
};

Incomplete types are also used for data hiding; the incomplete type is defined in a header file, and the body only within the relevant source file.

https://en.wikipedia.org/wiki/C_syntax#Incomplete_types

最新文章

  1. [curator] Netflix Curator 使用
  2. Nginx和PHP-FPM的启动/重启脚本 [转发]
  3. C#:屏幕显示区域问题
  4. 使用JavaScript实现新闻滚动效果
  5. TCL随记(2)
  6. Centos6.5安装
  7. python抓取网页图片
  8. 设计模式之八:外观模式(Facade)
  9. JavaScript(三)---- 控制流程语句
  10. Java 面试总结(一) —— 面试常问的关键字总结
  11. MySQL日期、时间相关内容
  12. iOS 使用GRMustache对HTML页面进行渲染
  13. grep -v、-e、-E
  14. 请求库之requests模块
  15. Linux_系统管理_网络配置_命令行配置网络
  16. JavaScript的基本包装类型说明
  17. html5手机移动端三级联动城市选择器
  18. ImageView android:scaleType="centerCrop"
  19. windows后门
  20. 1043 输出PATest

热门文章

  1. ibatiS启动的异常 The content of elements must consist of well-formed character data or markup
  2. java简单实现MD5加密
  3. How Google Backs Up The Internet Along With Exabytes Of Other Data
  4. CefSharp获取页面Html代码的两种方式
  5. 四、分布式 Git(未完待续)
  6. webpack配置相关的页面异常
  7. IDEA使用操作说明(自己总结)
  8. APP热更新方案(转)
  9. class.forName的官方使用方法说明
  10. 安卓更新Toast流程图