设为首页 加入收藏

TOP

2.9.2 A Brief Introduction to the Preprocessor (1)
2013-10-07 15:22:47 来源: 作者: 【 】 浏览:67
Tags:2.9.2 Brief Introduction the Preprocessor

Now that we know what we want to put in our headers, our next problem is to actually write a header. We know that to use a header we have to #include it in our source file. In order to write our own headers, we need to understand a bit more about how a #include directive works. The #include facility is a part of the C++(www.cppentry.com) preprocessor. The preprocessor manipulates the source text of our programs and runs before the compiler. C++(www.cppentry.com) inherits a fairly elaborate preprocessor from C. Modern C++(www.cppentry.com) programs use the preprocessor in a very restricted fashion.

EXERCISES SECTION 2.9.1

Exercise 2.31: Identify which of the following statements are declarations and which ones are definitions. Explain why they are declarations or definitions.

(a) extern int ix = 1024;

(b) int iy;

(c) extern int iz;

(d) extern const int &ri;

Exercise 2.32: Which of the following declarations and definitions would you put in a header In a source file Explain why.

(a) int var;

(b) const double pi = 3.1416;

(c) extern int total = 255;

(d) const double sq2 = sqrt(2.0);

Exercise 2.33: Determine what options your compiler offers for increasing the warning level. Recompile selected earlier programs using this option to see whether additional problems are reported.

A #include directive takes a single argument: the name of a header. The preprocessor replaces each #include by the contents of the specified header. Our own headers are stored in files. System headers may be stored in a compilerspecific format that is more efficient. Regardless of the form in which a header is stored, it ordinarily contains class definitions and declarations of the variables and functions needed to support separate compilation.

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇2.9.2 A Brief Introduction to t.. 下一篇5.3.2 Using the Shift Operators..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: