当前位置:网站首页>【C】 Compilation preprocessing and environment
【C】 Compilation preprocessing and environment
2022-06-11 18:00:00 【Penguins don't cry】

Catalog
One 、 Translation environment and execution environment
4. The comparison between macro and function
Preface

One 、 Translation environment and execution environment
The source file to the executable program must pass through the translation environment , The translation environment includes compilation and linking , Compile package precompile 、 compile 、 assembly . The source file is processed by the compiler to generate the target file (.obj), Object files and link libraries generate executable programs through linkers .

Two 、 compile + link
1. precompile
The essence is text operation :
1. The header file contains #include
2. Delete Note
3.#define Defines the substitution of symbols
2. compile
hold C Language into assembly code
1. Syntax analysis
2. Lexical analysis
3. Semantic analysis
4. Symbol summary
3. assembly
Convert assembly code into binary instructions :
4. Running environment
1. The program must be loaded into memory
2. Start execution , call main function
3. The program uses the run stack , Storage function local variable return address
4. To terminate the program
3、 ... and 、 Preprocessing
1. Defining symbols
__FILE__
__LINE__
__DATE__
__TIME__
__STDC__// Source files to compile
// The current line number of the file
// The date the file was compiled
// When the file was compiled
// If the compiler follows ANSI C, Its value is 1, Otherwise, it is not defined
2.#define
#define name( parament-list ) stuff
// Among them parament-list It's a list of symbols separated by commas , They may appear in stuff in
#define SQUARE( x ) x * x
// This macro takes a parameter x .
// If after the above statement , You put
SQUARE( 5 );
// Put in the program , The preprocessor will replace the above expression with the following expression
5 * 5Tips :
So the macro definitions used to evaluate numeric expressions should be bracketed in this way , Avoid using macros due to . Unexpected interactions between operators or adjacent operators .
3.# and ##
int i = 10;
#define PRINT(FORMAT, VALUE)
printf("the value of " #VALUE "is "FORMAT "\n", VALUE);
// Output results
the value of i+3 is 13//## You can combine the symbols on both sides of it into one symbol .
// It allows macro definitions to create identifiers from detached pieces of text .
#define ADD_TO_SUM(num, value)
sum##num += value;
ADD_TO_SUM(5, 10);// Role is : to sum5 increase 10.4. The comparison between macro and function

Naming conventions :
Capitalize all macro names
Do not capitalize all function names
5.#undef
#undef NAME
// If an existing name needs to be redefined , Then its old name must first be removed
6. Conditional compilation
#ifndef __TEST_H__
#define __TEST_H__
// Content of header file
#endif //__TEST_H__perhaps
#pragma onceThis is done to avoid duplicate definitions of header files . When the header file is included for the first time _TEST_H Because there's no definition , So satisfy ifndef_TEST_H, Define after executing downward _TEST_H. The next time the header file is included, it has already been defined _TEST_H, So I'm not satisfied ifndef_TEST_H. They don't execute #ifndef_TEST_H To #endif Part between .
summary
see 《 High-quality C/C++ Programming Guide 》 The test paper in the appendix .
边栏推荐
- Line up to pick up the express. At this meeting, I sorted out all kinds of code sets
- 论文阅读 dyngraph2vec: Capturing Network Dynamics using Dynamic Graph Representation Learning
- Online excel file parsing and conversion to JSON format
- 6-2 多个整数的逆序输出-递归
- 合并K个升序链表---2022/02/26
- Common shortcut keys for Hello go (x) and GoLand
- Bracket generation ---2022/02/25
- TestPattern error
- Typescipt Basics
- ForEach遍历集合、 集合容器
猜你喜欢

【先收藏,早晚用得到】100个Flink高频面试题系列(三)

Kubernetes deploys elk and collects container logs using filebeat

Use exe4j to convert The jar file is packaged as Exe file

tidb-写热点的测试及分析

which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_ mod

mysql8安装,navicat安装,sqli-labs搭建

mariadb spider分片引擎初體驗

MFSR:一种新的推荐系统多级模糊相似度量

Test basis: black box test

Leetcode force deduction question
随机推荐
Merge K ascending linked lists ---2022/02/26
Rtsp/onvif protocol easynvr video platform arm version cross compilation process and common error handling
6-8 创建、遍历链表
Port planning and APJ
6-5 count the number of words (file) (*)
Mathematical foundations of information security Chapter 3 - finite fields (I)
R language mice package error in terms Formula (TMP, simplify = true): the model formula in extractvars is incorrect
R语言寻找数据集缺失值位置
[foundation of deep learning] learning of neural network (3)
6-8 有结构文件的读写1
[collect first and use it sooner or later] 49 Flink high-frequency interview questions series (II)
adb 命令学习笔记
【实用脚本】获取某个文件的行号,然后删除文件内容。
Valid parentheses ---2022/02/23
Mathematical basis of information security Chapter 2 - congruence
有效的括号---2022/02/23
夜神安装apk,以及bp代理
6-2 写文章(*)
Can 400 fans earn 20W a month? How did you do it?
Service学习笔记04- 其他服务实现方式与替代方式