当前位置:网站首页>Program environment and pretreatment
Program environment and pretreatment
2022-06-29 00:22:00 【A river that is making efforts】
First look at what happened to the file , as follows :
This article is mainly about the translation environment .


It is mainly divided into the following parts :

(ps: To view the header file information, you can find the installation directory )

Precompile phase

compile

assembly


.o Is in linux Generated under the system ,.obj Is in Windows Generated under the system .
About the travel symbol table : Different symbols have addresses .

The function of the linker is to merge segment tables ;

The process of running a program :
Predefined symbols
__STDC__ // If the compiler follows ANSI C, Its value is 1, Otherwise, it is not defined


Write a log file



If you don't add a semicolon ,return 0 Will be taken as for The following statement . Running successfully . ( A special case )
It is better not to add a semicolon : Examples are as follows
if(condition)
max = MAX;
else
max = 0;There will be syntax errors .IF Only one statement can be followed .

The above code is risky

The solution is to add parentheses
![]()
Is the above code safe , Let's do another example
#define DOUBLE(x) (x) + (x)
int a = 5;
printf("%d\n" ,10 * DOUBLE(a));
printf ("%d\n",10 * (5) + (5));
This problem , The solution is to add a pair of parentheses around the macro definition expression .
#define DOUBLE( x) ( ( x ) + ( x ) )At present, I want to realize such a function :

When you want to enter different numbers ,a Is different .
Let's look at an example : Strings are naturally concatenated . The following three results are the same .



x+1;// No side effects
x++;// With side effects 
The result of this code is the same , But the second will change a Value .


The front is false , So execute b++.10>11 For false . after a Increase to 11,b Increase to 12, First use 12 after , add 1, Turn into 13.
The difference between functions and macros .



The macro passes a type .




#include <stdio.h>
#define __DEBUG__
int main()
{
int i = 0;
int arr[10] = {0};
for(i=0; i<10; i++)
{
arr[i] = i;
#ifdef __DEBUG__
printf("%d\n", arr[i]);// To see if the array assignment is successful .
#endif //__DEBUG__
}
return 0;
}See if it defines . Once defined, this statement will be executed .
Common conditional compilation instructions :
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
#endif 



Use macro definitions to implement

边栏推荐
- Test experience: how testers evolve from 0 to 1
- Is the compass stock software reliable? Is it safe to trade stocks on it?
- Remove HTML tags from Oracle
- 三个pwn题
- Encapsulation of JDBC connection and disconnection database
- websocket-js连接如何携带token验证
- [image registration] SAR image registration based on particle swarm optimization Improved SIFT with matlab code
- ES6模块
- oracle 去掉html标签
- 小白创业做电商,选对商城系统很重要!
猜你喜欢

由背景图缓存导致的canvas绘图跨域问题

6.28 学习内容

Give you a project, how will you carry out performance testing (I)

12. Détection d'objets Mask rcnn

Cross domain problem of canvas drawing caused by background image cache
![[buuctf.reverse] 131-135](/img/c2/b8b06c8191af2c75bf4ad5c82feaea.png)
[buuctf.reverse] 131-135

Realization of beauty system with MATLAB

随笔记:定义setter和getter的三种方式

Stm32f407 ------ serial (serial port) communication

Single machine multi instance MySQL master-slave replication
随机推荐
Windows平台下安装MySQL(附:Navicat Premium 12 “使用” 教程)
Is the fund reliable and safe
Use and principle of handlerthread
基于.NetCore开发博客项目 StarBlog - (13) 加入友情链接功能
Pinhole camera with added lens
Realization of beauty system with MATLAB
Zoom with mouse wheel
LinkedIn datahub - experience sharing
6.28 学习内容
Typescript-- section 4: Functions
Single machine multi instance MySQL master-slave replication
Reprint: VTK notes - clipping and segmentation - 3D curve or geometric cutting volume data (black mountain old demon)
三个pwn题
[image registration] SAR image registration based on particle swarm optimization Improved SIFT with matlab code
Stm32f407 ------ serial (serial port) communication
Three PWN questions
The company has a new Post-00 test paper king. The old oilman said that he could not do it. He has been
小白创业做电商,选对商城系统很重要!
三個pwn題
Daily question 1: missing numbers