当前位置:网站首页>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 .
边栏推荐
- 540. Single element in ordered array / 1684 Count the number of consistent strings
- Cloud picture says | distributed transaction management DTM: the little helper behind "buy buy buy"
- Record 3 - the state machine realizes key control and measures the number of external pulses
- Find all missing numbers in the array
- Check log4j problems using stain analysis
- Leetcode-83 删除排序链表中重复的元素
- Mysql database of easyclick
- Unity learning fourth week
- Facebook聊单,SaleSmartly有妙招!
- How to learn automated testing?
猜你喜欢

540. Single element in ordered array / 1684 Count the number of consistent strings

Explain in detail the process of realizing Chinese text classification by CNN

Fix the black screen caused by iPhone system failure

LiveData postValue会“丢”数据
![[image denoising] matlab code for removing salt and pepper noise based on fast and effective multistage selective convolution filter](/img/bf/f8759195ea67832835e84c851b5e81.jpg)
[image denoising] matlab code for removing salt and pepper noise based on fast and effective multistage selective convolution filter

Facebook聊单,SaleSmartly有妙招!

3、《创建您自己的NFT集合并发布一个Web3应用程序来展示它们》在本地铸造 NFT

PTA year of birth

1380. Lucky number in matrix / 1672 Total assets of the richest customers

Growing up in the competition -- (Guangyou's most handsome cub) Pikachu walking
随机推荐
Is it safe to open a securities account? Is there any danger
Facebook聊单,SaleSmartly有妙招!
How to manage 1000 anchors by one person?
Draw drawing process of UI drawing process
Yolov5 practice: teach object detection by hand
Blue Bridge Cup real question: score statistics
R语言epiDisplay包ordinal.or.display函数获取有序logistic回归模型的汇总统计信息(变量对应的优势比及其置信区间、以及假设检验的p值)、write.csv函数保存csv
信度系数低怎么办?信度系数具体怎么算?
LeetCode 148. Sort linked list
Weekly recommended short videos: be alert to the confusion between "phenomena" and "problems"
Basic usage of shell script
Batch export all pictures in PPT in one second
Leetcode problem solving series -- continuous positive sequence with sum as s (sliding window)
Using OpenSSL encryption to rebound shell traffic
540. Single element in ordered array
LiveData postValue会“丢”数据
t10_ Adapting to Market Participantsand Conditions
ZABBIX alarm execute remote command
JS how to convert a string with a delimiter into an n-dimensional array
Small exercise -- subnet division and summary