当前位置:网站首页>Reading notes series "modern methods of C language programming" -- Chapter 2
Reading notes series "modern methods of C language programming" -- Chapter 2
2022-07-01 18:39:00 【Deer nine pills】
Chapter two C Basic concepts of language
2.1 Write a simple one C Program
2.1.1 Compile and link
- Preprocessing : First, the program will be submitted to The preprocessor . The preprocessor executes to # The instructions at the beginning ( It is often called an instruction ). The preprocessor is a bit like an editor , It can add content to the program , You can also modify the program ( For example, modify the name of the main function ).
- compile . The modified program can now enter the compiler . The compiler will translate the program into machine instructions ( I.e. target code ). However , Such a program still cannot run .
- link . In the last step , The linker integrates the object code generated by the compiler with other additional code required , Only in this way can we finally produce a fully executable program . These additional codes include library functions used in the program .
2.2.1 Instructions
Instructions : We call the commands executed by the preprocessor instructions . All instructions are written in characters # At the beginning . By default, the instruction occupies only one line , There is no semicolon or other special mark at the end of each instruction .
2.2.2 function
One C A program can contain multiple functions , But only main() Functions are required , When executing the program, the system will automatically call main() function .
return 0; The role of :
- send main() Function termination ( This ends the program ).
- Pointed out that main The return value of the function is 0.
Be careful : If main() There is no at the end of the function return sentence , The program can still terminate . But many compilers produce a warning message ( Because the function should return an integer, but it doesn't ).
2.4.3 assignment
When we assign a constant containing a decimal point to float Type variable , It is best to add a character after the constant f( representative float).
2.7 identifier
Some compilers put specific identifiers ( Such as asm) Treat as additional keywords . Identifiers belonging to the standard library are also restricted . Misuse of these names may lead to compilation or link errors . Identifiers that begin with underscores are also restricted .
Q & A
ask : In some C In the language book ,main() The function ends with exit(0) instead of return 0, Are they the same ?
answer : When it appears in main() Function to make , These two statements make completely equivalent , Both terminate program execution , And return to the operating system 0 value . Which statement to use depends entirely on your personal preferences .
ask : If main() There is no... At the end of the function return What are the consequences of statements ?
answer :return Statement is not necessary ; without return sentence , The program will also terminate . stay C89 in , The value returned to the operating system is undefined . stay C99 in , If main() The return type in the function declaration is int, The program will return to the operating system 0; Otherwise, an indefinite value will be returned .
ask : Does the compiler remove comments completely or replace them with spaces ?
answer : Some early compilers deleted all fields in each comment , Make the statement
a/**/b = 0;
Comprehend
ab = 0;
However , basis C standard , The compiler must replace each comment statement with a space character , Therefore, the techniques mentioned above are not feasible .
We'll actually get the following statement :
a b = 0;
ask : Is there really no limit on the length of identifiers ?
answer : yes , Not yet .C89 The standard declaration identifier can be any length , But it is worth asking the compiler to remember before 31 Characters (C99 Medium is 63 Characters ). therefore , If the first two names 31 All characters are the same , The compiler may not be able to distinguish them .
More complicated is ,C The standard has special provisions for the identifier of external links , Most function names are such identifiers . Because the linker must be able to recognize these names , Some early linkers could only handle short names , So in C99 Only before 6 Characters are valid . Besides , Not case sensitive yet . therefore ABCDEFG and abcdefg May be treated as the same name .(C99 in , front 31 Characters are valid , And the letters are case sensitive .)
Most compilers and linkers are looser than the standard requires , So these rules are not a problem in practical use , Don't worry about identifiers being too long , Don't define them too short .
边栏推荐
- 必看,时间序列分析
- Win10+vs2019 Community Edition compiling OpenSSL
- 540. Single element in ordered array
- Financial judgment questions
- [image denoising] matlab code for removing salt and pepper noise based on fast and effective multistage selective convolution filter
- [CF559E]Gerald and Path
- Nearly 60% of the employees strongly support Ctrip's "3+2" working mode, and work at home for two days a week
- R语言使用epiDisplay包的tableStack函数制作统计汇总表格(基于目标变量分组的描述性统计、假设检验等)、不设置by参数则计算数据框指定数据列范围的基础描述性统计信息
- R语言caTools包进行数据划分、scale函数进行数据缩放、class包的knn函数构建K近邻分类器、table函数计算混淆矩阵
- GAMES202作业0-环境搭建过程&解决遇到的问题
猜你喜欢
PTA year of birth
[source code analysis] NVIDIA hugectr, GPU version parameter server - (1)
6款红黄黑榜摄像头评测:谁最安全?谁画质好?从此让你不再踩雷
关于企业中台规划和 IT 架构微服务转型
. Net cloud native architect training camp (permission system code implements actionaccess) -- learning notes
LeetCode-21合并两个有序链表
Principal component calculation weight
Sum of three numbers
Facebook聊单,SaleSmartly有妙招!
How to retrieve the password for opening Excel files
随机推荐
Growing up in the competition -- (Guangyou's most handsome cub) Pikachu walking
. Net cloud native architect training camp (permission system code implements actionaccess) -- learning notes
Relationship between sensor size, pixel, dpi resolution, inch and millimeter
Yuancosmos game farmersworld farmers world - core content of the second conference in China!
Bug of QQ browser article comment: the commentator is wrong
Sanfeng cloud 0215 I often use
Fix the problem that easycvr device video cannot be played
Must see, time series analysis
Basic concepts of binary tree
Mujoco XML modeling
信度系数低怎么办?信度系数具体怎么算?
When the fixed frequency artifact falls in love with multithreading | ros2 fixed frequency topic release demo
[noip2015] jumping stone
Implementation of converting PCM file to WAV
LiveData postValue会“丢”数据
Leetcode 1380. Lucky numbers in the matrix (save the minimum number of each row and the maximum number of each column)
What if the reliability coefficient is low? How to calculate the reliability coefficient?
The method of real-time tracking the current price of London Silver
540. Single element in ordered array / 1684 Count the number of consistent strings
R语言epiDisplay包ordinal.or.display函数获取有序logistic回归模型的汇总统计信息(变量对应的优势比及其置信区间、以及假设检验的p值)、write.csv函数保存csv