当前位置:网站首页>C language - program compilation
C language - program compilation
2022-07-27 06:23:00 【Autumn mountain chariot God AE】
C Program translation environment and execution environment .
Translation environment refers to the environment that converts source files into executable machine instructions , The execution environment is used to actually execute code .
In the translation environment , Each source file is converted into object code through compilation (obj), The target files are bound together by linkers
, Form a single executable program , The linker also links the functions in the function library to the program .
Compilation is divided into precompile ( Preprocessing ), compile , Assemble three stages .
In the precompile phase , Put the included header code into the source file , Conduct define Substitution of defined symbols , And the deletion of comments .
In the compilation phase , Through grammatical analysis , Semantic analysis , Lexical analysis , Symbol summary C Language code is translated into assembly language code .
In the assembly phase , Translate assembly language code into machine language .
Preprocessing instruction
// These predefined symbols are built into the language .
__FILE__ // Source files to compile
__LINE__ // The current line number of the file
__DATE__ // The date the file was compiled
__TIME__ // When the file was compiled
__STDC__ // If the compiler follows ANSI C, Its value is 1, Otherwise, it is not defined #define
Use define Define the indicator
#define name stuff#define When defining an identifier , Better not add ;
Use #define Allow parameters to be replaced with text , This definition is called macro definition .
for example
#define SQUARE( x ) x * xHowever, macro definitions used to evaluate numeric expressions should be properly bracketed , Avoid using macros due to operations in parameters
Unpredictable interactions between operators or adjacent operators .
#define The replacement rule of
1. When calling a macro , First, check the parameters , See if it contains any information from #define Defined symbols . If it is , Their head
Replaced first .
Conditional compilation
1.
#if Constant expression
//
#endif
// Constant expressions are evaluated by the preprocessor .
Such as :
#define __DEBUG__ 1
#if __DEBUG__
//..
#endif
2. Conditional compilation of multiple branches
#if Constant expression
//...
#elif Constant expression
//...
#else
//...
#endif
3. Judge whether it is defined
#if defined(symbol)
#ifdef symbol
#if !defined(symbol)
#ifndef symbol
4. Nested instruction
#if defined(OS_UNIX)
#ifdef OPTION1
unix_version_option1();
#endif
#ifdef OPTION2
unix_version_option2();
#endif
#elif defined(OS_MSDOS)
#ifdef OPTION2
msdos_version_option2();
#endif
#endifThe header file contains
The local file contains :
#include "filename"#include <filename.h>#ifndef __TEST_H__
#define __TEST_H__
// Content of header file
#endif //__TEST_H__perhaps
#pragma once边栏推荐
- 机器人导航实现
- 多坐标变换
- Code implementation and introduction of all commonly used sorting
- Li Kou daily question (linked list simulation)
- Remote sensing image recognition misclassification under multi class recognition
- Dynamic programming for solving problems (1)
- Robot navigation
- 数据库的联合查询
- UnityShader-高斯模糊
- 学习软件测试时需要配备的运行环境需求搭建
猜你喜欢

What is the difference between single line and three line when renting servers in Hong Kong?

wireshark数据包修改--IP地址修改(一)

Navigation related messages

Brief introduction to unity window interface

UnityShader-高斯模糊

How to choose the correct server backup method

Unity shader overview

多线程的相关知识

多坐标变换

Ulcl function --5gc
随机推荐
jmeter简介
IP核小结
通信机制案例
数据库在终端的增删改查
Header and source files in ROS
Reading and writing of file content - data flow
Remote sensing image recognition - making data sets
多线程常见锁的策略
Pzk's first understanding of pointer in learning C language
Programming learning records - Lesson 4 [branch and loop statements]
The problem that tqdm cannot display in a single line
Some experience of learning technology and theoretical knowledge
Related knowledge of multithreading
Li Kou's first week's wrong question set
Interpretation of unity desktop version 7.6
TF coordinate transformation
5G的前世今生---简述移动通信的发展
Wireshark function introduction
ROS workspace coverage
Robot navigation