当前位置:网站首页>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 .
边栏推荐
- Depth first search - DFS (burst search)
- 540. Single element in ordered array
- When the fixed frequency artifact falls in love with multithreading | ros2 fixed frequency topic release demo
- How to manage 1000 anchors by one person?
- Blue Bridge Cup real question: score statistics
- Develop those things: add playback address authentication to easycvr platform
- Weekly recommended short videos: be alert to the confusion between "phenomena" and "problems"
- Pytorch crossentropyloss learning
- Leetcode problem solving series -- continuous positive sequence with sum as s (sliding window)
- Five degrees easy chain enterprise app is newly upgraded
猜你喜欢
Lumiprobe 生物分子定量丨QuDye 蛋白定量试剂盒
A wonderful time to buy and sell stocks
What if the reliability coefficient is low? How to calculate the reliability coefficient?
2、《创建您自己的NFT集合并发布一个Web3应用程序来展示它们》启动并运行您的本地环境
Mujoco XML modeling
PTA year of birth
Leetcode-141环形链表
Happy new year | 202112 monthly summary
每周推荐短视频:警惕“现象”与“问题”相互混淆
12 data dimensioning processing methods
随机推荐
力扣每日一题-第32天-1232. 缀点成线
Thread forced join, thread forced join application scenarios
Is Alipay wallet convenient to use?
Depth first search - DFS (burst search)
Subnet division and summary
GAMES202作业0-环境搭建过程&解决遇到的问题
JS how to convert a string with a delimiter into an n-dimensional array
Leetcode203 移除链表元素
Search 2D matrix 2
Win10+vs2019 Community Edition compiling OpenSSL
Extract the compressed package file and retrieve the password
How to manage 1000 anchors by one person?
LiveData postValue会“丢”数据
SCP -i private key usage
Sum of three numbers
R语言使用epiDisplay包的dotplot函数通过点图的形式可视化不同区间数据点的频率、使用pch参数自定义指定点图数据点的形状
MySQL connection tools
Computer network interview assault
Basic concepts of binary tree
[CF1476F]Lanterns