C Language Study Notes (11)

Source: Internet
Author: User

1. Conditional compilation

Conditional compilation means that preprocessing is included or excluded based on the test results.Program.

2. # If and # endif

Let's not talk about it. Let's just give an example.

 
# DefineDebug 1IntMain (Void){# IfDebug printf ("Hello World");# Endif return0 ;}

In fact, the effect is similar to thisCode:

 
IntMain (Void){IntDEBUG = 1;If(Debug) printf ("Hello World");Return0 ;}

The difference is that pre-processing commands are processed by the pre-processor. # The if command tests the debug value. If the debug value is 0, the printf will not save the space occupied by the target program, nor will it consume the running time of the program. Therefore, we can save this code to the final code during the test.

3. Compile symbols with similar conditions

The defined operator is usually used together with # If to determine whether a macro definition is defined.

 
# DefineDebug 1IntMain (Void){# If definedDebug printf ("Hello World");# Endif return0 ;}

The same semantics can also be written as follows:

 
# DefineDebug 1IntMain (Void){# IfdefDebug printf ("Hello World");# Endif return0 ;}

Of course, # ifndef stands for the semantics of if not defined.

# Elif: else if

# Else.

These can be used together with # If, and are the same as general condition judgment semantics. I will not repeat the example.

4. Usage of Conditional compilation

A. debugging.

B. Compile programs used by different operating systems, platforms, and compilers.

For example:

 
# DefineWindowsIntMain (Void){# If definedWindows printf ("Windows");# Elif definedLinux printf ("Linux");# ElsePrintf ("Else");# Endif return0 ;}

C. Temporarily shield code

5. # error command

# Error indicates a serious error. The Compiler immediately terminates the program. For example:

IntMain (Void){# If definedWindows printf ("Windows");# Elif definedLinux printf ("Linux");# Else # errorNot support# Endif return0 ;}

6. Managed and independent implementations

This is a basic concept.

Most programs are managed. These programs require the underlying operating system to provide input and output and some other basic services. The independent implementation of C is used for programs that do not require an operating system.

In general, standalone programs are used to write the operating system kernel and embedded programs.

 

 

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.