当前位置:网站首页>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边栏推荐
- Navigation related messages
- shell script if嵌套for循环脚本
- [dynamic planning - steel bar cutting]
- 兼容性测试知识点
- Remote sensing image recognition misclassification under multi class recognition
- wireshark数据包修改--IP地址修改(一)
- Li Kou daily question leetcode 513. find the value in the lower left corner of the tree
- Understand the pointer in a picture
- wireshark功能介绍
- 多线程的知识补充
猜你喜欢
随机推荐
Programming learning records - Lesson 4 [branch and loop statements]
Remote sensing image recognition training strategy
无法启动程序,拒绝访问?
数据库命令
ULCL功能--5GC
Strategies for common locks in multithreading
Dynamic planning for solving problems (3)
软件测试用里篇
PLL of IP core
Tangent space and TBN matrix
单元集成(接⼝)测试
遥感影像识别-多类识别下的错分问题
多线程的知识补充
Operate access database based on WinForm of C (at the end of MDB)
Man moon myth reading notes
Related knowledge of internal classes
socket 长链接
IP核之ROM
多坐标变换
多线程常见锁的策略









