当前位置:网站首页>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 .
边栏推荐
- This is the latest opportunity of the London bank trend
- [today in history] February 15: Pascal's father was born; YouTube was founded; Kotlin language comes out
- Redis master-slave realizes 10 second check and recovery
- Static timing analysis (STA) in ic/fpga design
- Develop those things: add playback address authentication to easycvr platform
- Mysql database design
- Vue uses keep alive to cache page optimization projects
- t10_ Adapting to Market Participantsand Conditions
- Distributed task queue: Celery usage record
- Thread forced join, thread forced join application scenarios
猜你喜欢

Case study on comprehensive competitiveness of principal components

LeetCode 148. Sort linked list

Basic concepts of binary tree

每周推荐短视频:警惕“现象”与“问题”相互混淆

Cloud picture says | distributed transaction management DTM: the little helper behind "buy buy buy"

信度系数低怎么办?信度系数具体怎么算?

Leetcode-141环形链表

Highly reliable program storage and startup control system based on anti fuse FPGA and QSPI flash

每周推薦短視頻:警惕“現象”與“問題”相互混淆

Leetcode-160相交链表
随机推荐
信度系数低怎么办?信度系数具体怎么算?
12. Design of power divider for ads usage record
PCL learning materials
Fix the black screen caused by iPhone system failure
A wonderful time to buy and sell stocks
Localization through custom services in the shuttle application
每周推薦短視頻:警惕“現象”與“問題”相互混淆
Domestic spot silver should be understood
研究了11种实时聊天软件,我发现都具备这些功能…
Five degrees easy chain enterprise app is newly upgraded
Vidéos courtes recommandées chaque semaine: méfiez - vous de la confusion entre « phénomène » et « problème »
Leetcode-128 最长连续序列
LiveData postValue会“丢”数据
Flex layout
Mujoco's biped robot Darwin model
Nearly 60% of the employees strongly support Ctrip's "3+2" working mode, and work at home for two days a week
Highly reliable program storage and startup control system based on anti fuse FPGA and QSPI flash
12种数据量纲化处理方式
Step size of ode45 and reltol abstol
How to retrieve the password for opening Excel files