Chinaunix首页 | 论坛 | 博客
  • 博客访问: 359778
  • 博文数量: 100
  • 博客积分: 2500
  • 博客等级: 大尉
  • 技术积分: 1209
  • 用 户 组: 普通用户
  • 注册时间: 2011-04-15 21:24
文章分类

全部博文(100)

文章存档

2011年(100)

分类: C/C++

2011-04-19 14:22:32

Preprocessor directives are lines included in the code of our programs that are not program statements but directives for the preprocessor. These lines are always preceded by a hash sign (#). The preprocessor is executed before the actual compilation of code begins, therefore the preprocessor digests all these directives before any code is generated by the statements.

#define #undef
To define preprocessor macros we can use #define
A macro lasts until it is undefined with the #undef preprocessor directive

#ifdef #ifndef #if #endif #else #elif
These directives allow to include or discard part of the code of a program if a certain condition is met.

#line
The #line directive allows us to control both things, the line numbers within the code files as well as the file name that we want that appears when an error takes place.
  1. #line number "filename"

#error
This directive aborts the compilation process when it is found, generating a compilation the error that can be specified as its parameter

#include
When the preprocessor finds an #include directive it replaces it by the entire content of the specified file.
  1. #include "file"
  2. #include <file>
In the first case where the file name is specified between double-quotes, the file is searched first in the same directory that includes the file containing the directive. In case that it is not there, the compiler searches the file in the default directories where it is configured to look for the standard header files.
If the file name is enclosed between angle-brackets <> the file is searched directly where the compiler is configured to look for the standard header files.

#pragma
This directive is used to specify diverse options to the compiler.

macro name:


  1. #include <iostream>
  2. using namespace std;

  3. int
  4. main(void)
  5. {
  6.         cout << "This is the line number " << __LINE__;
  7.         cout << " of file " <<__FILE__<< endl;
  8.         cout << "Its compilation began " <<__DATE__;
  9.         cout << " at " <<__TIME__<< endl;
  10.         cout << "The complier gives a __cplusplus value of " <<__cplusplus << endl;

  11.         return (0);
  12. }

阅读(901) | 评论(0) | 转发(0) |
0

上一篇:类型转换

下一篇:文件I/O

给主人留下些什么吧!~~