Home  >  Article  >  Backend Development  >  When is macro expansion performed in C programs?

When is macro expansion performed in C programs?

烟雨青岚
烟雨青岚Original
2020-06-22 15:39:515909browse

When is macro expansion performed in C programs?

#When is macro expansion performed in the c program?

Macro expansion is performed in the preprocessing stage.

The three stages in which a C program changes from a source program to an executable file are:

The preprocessing stage, in which the preprocessor expands the macros in the program text.

In the compilation stage, the compiler compiles the preprocessed program and generates the target file

In the link stage, the linker links the target file and the used function library file , generate an executable file.

Therefore, macro expansion is done in the preprocessing stage.

When is macro expansion performed in C programs?

Extended information:

Macro definition

Macro definition is one of the three preprocessing functions provided by C 1: Macro definition, file inclusion and conditional compilation

No parameter macro definition:

Macro definition is also called macro substitution, macro substitution, referred to as "macro".

Format: #Define identifier string

Identifiers are called symbolic constants, also known as "macro names".

Preprocessing (precompilation) is also called macro expansion: replacing macro names with strings.

The key to mastering the concept of macros is substitution. Everything is predicated on change. You must change before doing anything, and accurately understand the necessity of "change".

The complex ones are as follows. The following macro definitions have parameters, and there are many multi-line macro definitions in the Linux kernel source code.

sizeof is also a macro definition.

Recommended tutorial: "C Language"

The above is the detailed content of When is macro expansion performed in C programs?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn