Program-C language details 15 (preprocessing command details # error, operator # And #, _ FILE _, _ LINE __)
Main Content: preprocessing command details # error, operator # And #, _ FILE _, _ LINE __
# Include
/* Contains this header file, instead of linking all its functions to the Program * // * # Operator */# define MK_ID (n) I # n/* Indicates connecting two marks */int MK_ID (1), MK_ID (2), MK_ID (3);/* after preprocessing, it becomes int i1, i2, i3; * // * defines multiple types ##_ max functions. The return type and parameter type of the function are determined by define. * For example, GENERIC_MAX (int) is converted into int int_max (int x, int y) {return} return x> y? X: y; */# define GENERIC_MAX (type) \ type ##_ max (type x, type y) \ {\ return x> y? X: y; \}/* parentheses must be added if the macro definition contains parameters, as follows: */# define THREE_PI (3*3.1415) # define TEST (x) (x) * 10)/* # error usage. error indicates a serious error, most compilers immediately stop compiling */# if INT_MAX> 100000 # error int type is too small # endif/* # line command to change the row numbering method for the program, usually the numbers are 1, 2, 3 ,.... * // * # The operator converts a macro parameter to a string literal. */# define PRINT_INT (x) printf (# x "= % d \ n", x) /* The result is PRINT_INT (I/j) => printf ("I/j" "= % d \ n", I/j) => output I/j = 5 * // * # occupies a single row. It is a so-called empty command and does not work, some program ape is used to give the interval between Conditional compilation modules */# if INT_MAX> 1000 # error int # endif/* Conditional compilation */# define DEBUG/* No need for debugging A value */# if defined (DEBUG) # endifint main (int argc, char * argv []) {int I = 10, j = 2; PRINT_INT (I/j ); printf ("Compiled on % s at % d \ n" ,__ FILE __,__ LINE _);/* _ FILE _ indicates the current FILE, __line _ indicates the current LINE, which is used well during debugging, especially when the embedded linux driver */printf ("% s | % s \ n" ,__ DATE __, __time _);/* also has _ DATE ,__ TIME _ TIME */printf ("% d \ n" ,__ STDC __); /* _ STDC _ check whether the compiler results in Standard C. If yes, 1 */return 0 is returned ;}
Output: