c ++ pre-compiler macros
1. The concept of pre-compiled macro
Some Microsoft official language:
. At The Visual C ++ Compiler predefines Certain Preprocessor Macros, DEPENDING ON at The Language (C or C ++), at The Compilation target, and at The Chosen Compiler Options
VC ++ compiler to pre-define some preprocessor macros, which depending on language, compiler and the selected target editor options
precompiled generally macro " __
" and ending with " __
" at the end, in the middle of all uppercase words, if a plurality of words composed of, between using the word " _
" connected.
2.__FILE__
__FILE__
: Displays the current name of the source file.
When will this macro function on and on macro generated is not the same result.
head File:
#include<iostream>
using namespace std;
#define HR(){cout<<__FILE__<<":in #define"<<endl;}
void TestFile();
Source File
#include"Test.h"
void TestFile() {
cout << __FILE__<<":in function"<<endl;
}
Test file
int main()
{
TestFile();
HR();
return 0;
}
Test Results
Conclusion: The macro __FILE__
file name indicates the call, the function to specify a file name to achieve
3.__LINE__
__LINE__
: Displays the current file executed
when the macro will be placed on the macro function and is produced different results.
Can refer to the __FILE__
usage, the next three files are given
#include<iostream>
using namespace std;
#define HR(){cout<<__LINE__<<":in #define"<<endl;}
void TestFile();
#include"Test.h"
void TestFile() {
cout << __LINE__<<":in function"<<endl;
}
int main()
{
TestFile();
HR();
return 0;
}
Conclusion: The macro __LINE__
file name indicates the call, the function to specify a file name to achieve