C-language Learning notes-conditional compilation

Source: Internet
Author: User

Conditional compilation in C language behaves like if...else in C ... , which is a precompiled instruction command that controls whether a piece of code is compiled.

1. Nature of conditional compilation

(1) pre-compiler selective deletion code based on conditional compilation directives

(2) The compiler does not know the existence of the Code branch

(3)if...else ... statements are branched at run time, and conditional compilation directives are branch-judged during the pre-compilation period.
(4) You can define macros from the command line

①gcc –DMarco=value file.c// for #if statements

②gcc –DMarco file.c// for #ifdef or ifndef statements

2. Meaning of conditional compilation

(1) conditional compilation allows us to compile different pieces of code according to different conditions, thus producing different target generations .code.  

(2)#if ... #else ... #endif is processed by the precompiled compiler, and if...else ... statements are processed by the compiler, and must be compiled Translate into target code.  

(3) in the actual project, the conditional compilation is mainly used in the following two kinds of situations:

① The different product lines share a piece of code

② differentiate between debug and release versions of compiled products

C-language Learning notes-conditional compilation

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.