导航

More preprocessor features

The preprocessor will be better way to handle following issues:
1. stringizing
    Stringizing performed with the # directive and allowing you to taken an identifier and turn it into a character array.
2. string concatenation
    String concatenation takes place when two adjacent character arrays have no intervening punctuation, in which case they are  
    combined.
3. token pasting.
   Token pasting, implemented with the ## directive, is very useful when you are manufacturing code. It allows you to take two identifiers and paste them together to automatically create a new identifier.
#define FIELD( a ) char *a##_string; int a##_size
class Record{ 
    FIELD( one);
    FIELD( two);
    FIELD( three);

};


Examples:
#define MYT(x) cout<< #x " = "<< x <<endl
MYT( 23 ) // 23 = 23

#define MYT(x, y) cout<< #x " = "<< y <<endl
MYT( 24, 23) // 24 = 23
MYT( "aa", 24) // "aa" = 24

posted on 2005-03-31 10:53  Raker  阅读(77)  评论(0)    收藏  举报