Main content: preprocessing command details #error, operator # and # #, __file__, __line__
#include <stdio.h>/* Contains this header file, not all of its functions are linked to the program */* # #运算符 */#define MK_ID (n) i# #n/* means to connect two tokens */int mk_id (1), MK_ID (2), mk_id (3); /* after preprocessing to int i1,i2,i3;*//* define multiple type# #_max函数, function return type and parameter type are determined by define * such as Generic_max (int) is int int_max (int x, int y) {return }return x > y? x:y; */#define GENERIC_MAX (type) type type# #_max (type x, type Y) {return x > y x:y;} /* If you have parameters in the macro definition, parentheses are required, as follows: */#define THREE_PI (3*3.1415) #define TEST (x) ((x) *10)/* #error用法, error indicates a critical error, most compilers stop compiling immediately */#if Int_max > 100000#error INT type is too small #endif/* #line指令用来改变给程序的行编号方式, usually numbered 1,2,3,....*//* #运算符将一个宏的参数转换为字符 string literal */#define PRINT_INT (x) printf (#x "=%d\n", x)/* effect is print_int (i/j) ==>printf ("i/j" "=%d\n", i/j) ==> output i/j = 5* /* #单独占一行, is called null instruction, does not have any effect, some program apes are used to give the interval between the conditional compilation module */#if int_max > 1000# #error int# #endif/* Conditional compilation */#define DEBUG/* Does not need to give D Ebug a value */#if defined (DEBUG) #endifint main (int argc, char* argv[]) {int i = ten, j = 2; Print_int (i/j);p rintf ("Compiled on%s at%d \ n", __fiLE__,__LINE__); /* __FILE__ represents the current file, __line__ represents the current line and is well debugged, especially in the embedded Linux driver */printf ("%s | | | %s \ n ", __date__,__time__); /* There are __date__ dates, __time__ time */printf ("%d\n", __stdc__); /* __stdc__ See if the compiler results in standard C, and accept returns 1*/return 0;}
Output:
Program Ape--c Language details 15 (preprocessing command details #error, operator # and # #, __file__, __line__)