Programmer --- C language details 31 (# define and # undef macro details, # error, # pragma message (& amp; quot; text & amp; quot;), macro definition comments)

Source: Internet
Author: User

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:


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.