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.
#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.
- #include "file"
-
#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:
- #include <iostream>
-
using namespace std;
-
-
int
-
main(void)
-
{
-
cout << "This is the line number " << __LINE__;
-
cout << " of file " <<__FILE__<< endl;
-
cout << "Its compilation began " <<__DATE__;
-
cout << " at " <<__TIME__<< endl;
-
cout << "The complier gives a __cplusplus value of " <<__cplusplus << endl;
-
-
return (0);
-
}
阅读(940) | 评论(0) | 转发(0) |