Tuesday, October 21, 2008

UsingPretreatment

Marco:
#define NAME rest of line
where NAME is encountered as a token, it is replace by rest of line.
ex:
named = NAME//named = rest of line

#define MAC(x,y) argument1:x argument2:y
when MAC is used,two argument strings must be presented. They will replace x and y when MAC() is expanded.
ex:
expanded = MAC(foo bar, yuk yuk)//expanded = argument1:foo bar argument2:yuk yuk

ATTENTION: marco is NOT function. marco names can NOT be overloaded, and the macro preprocessor can NOT handle recursive calls.do NOT using them unless you have to. they just simply rearrange the program text before the compiler sees it. following the convention to name macros using lots of CAP letters.

#undef X
ensures that no macro called X is defined.

Conditional Compilation:
#ifdef EXPRESSION1
statement1
#endif
for the compiler to see statement1 unless a macro called EXPRESSION1 has been #defind.

#ifndef EXPRESSION2
statement2
#endif
for the compiler to see statement2 unless a macro called EXPRESSION2 hasnot been #defind.

#if EXPRESSION3
statement3
#elif EXPRESSION4
statement4
#else
statement5
#endif
for the compiler, if EXPRESSION3 is true(not 0), compile statement3. or if EXPRESSION4 is true, compile statement4. if all of them is not true, then comiple statement5.

Including File Compilation:
#include < iostream>//standard library header file
#include < iostream.h>//old-style standard library header file
#include "IO.h" //user identitiy header file
#include "../file.h" //header file under unix parent directory
#include "/usr/local/file.h" //complete path name under unix
#include "..\file.h" //header file under dos parent directory
#include "\usr\local\file.h" //complete path name under dos

difference between #include<...> and #include"..."
#include <...> //compiler starts to search form standard library path name
#include "..." //compiler starts to search form user working path name

--------------------------------------------------------------------------------

not just those pretreatments are in cpp. but they are the most famous we see. they are too powerful to easy to lose control. i suggest thinking again before you use them. but, unfortunately, we have to use them a lot. so it is importance that design before you writing. whatever, programing is not a easy, we have to keep workhard.

No comments:

Post a Comment