Program Cycle and preprocessing

Source: Internet
Author: User

Process: pre-processing, compiling, connecting

1, pre-processing: not C + + statements, not add; must start with #

2, compile: First analysis after synthesis, storage allocation, target code generation

3, Connection: relocation between different files processing

preprocessing commands

{macro definition, file contains, conditional compilation}

One, the macro definition

Replace a macro name with a character literals

1. Macros with no parameters

#define Macro Name character text

(1) The name of the macro is named by the identifier, generally all uppercase, the character Rune can be any (including Key Words )

(2) String constants, part of an identifier is not replaced (just part of the whole)

(3) The same macro should not be defined more than once, first canceled, then defined, #undef

(4) The scope of the macro: Start with # define and end with #undef (default to the end of the source program)

(5) Macros are typically defined at the beginning or the header file

(6) Macro definitions allow nesting, meaning that defined macro names can be referenced in character literals

2. Macros with parameters

#define Macro Name (parameter table) character text

(1) There is no space between the macro name and the parentheses, otherwise it is understood

(2) Replace the parameters first

Second, the document contains

1, <> only in the system path lookup, call the standard library

2, "" First in the project to find, and then in the system to find, call their own written header files

3. Header files typically contain: function declarations, global constants, global variables, type declarations, macro definitions

Third, conditional compilation

1. #define定义条件

2, #ifdef, #ifndef

#define    // defined first, regardless of the value
#ifdef criteria Field ... // Program code One #else ... // Program code two #endif

Ifndef is the opposite of ifdef.

3. #if

#if  Constant expression  //can only use define expressions     ... // Code Snippet 1 #elif ...   // Code Snippet 2 #else ...   // Code Snippet 3 #endif

4, # ifdef=# if defined; #ifndef = #if!defined;

Iv. Other Orders

1. #error: Display information and stop compiling

2. #pragma once: only one time (open) is included at compile time

3. #line

Program Cycle and preprocessing

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.