Programmer --- C language details 31 (# define and # undef macro details, # error, # pragma message (& quot; text & quot;), macro definition comments)
Main Content: # define and # undef macro details
I. # define and # undef macro details
Macro life cycle starts from # define to # undef ends
Ii. # error
When compiling a program, you only need to encounter # error to generate an output error message and stop compiling.
Iii. # pragma message ("text information ")
When many macros are defined in the program to control the source code, you may forget whether these macros are correctly set. You can use the following code to determine
Iv. macro definition comments
Not feasible. See the program.
# Include
# Define BSC // # define BMC/* # define EMC */# define _ RUN # define ewaece # define sizeof // The following compilation error occurs, the above two can be compiled through // # define int # if 0 # When an error occurs during program compilation, the output error message is generated and the compilation is stopped # endifint main () {// BSC mmmm // BMC daew EMC // annotation takes precedence over macro definition preprocessing. When the annotation has been processed before the macro is expanded, this is when the macro is expanded. // and/**/will cause an error # define r 1 // # spaces can be set between define and define, # define does not have to start at/* # pragma message ("message text") * When we define many Macros in the program to control the source code, you may forget whether these macros are correctly set *. You can use the following code to determine */# ifdef _ RUN # HPA Gma message ("_ RUN macro activated! ") # Endif # define X 3 # define y x * 2 # undef X # define X 2 int z = Y; printf (" z = % d \ n ", z ); return 0 ;}
Output: