深入理解计算机系统:1.3 了解编译系统是如何工作是很有必要的(It Pays to Understand HowCompilation Systems Work)

本文探讨了程序员为何需要了解编译系统工作原理,包括优化程序性能、理解链接时错误及避免安全漏洞等方面。通过实例讲解不同C语言结构如何转化为机器码,并提供提升程序效率的方法。

1.3 了解编译系统是如何工作是很有必要的(It Pays to Understand HowCompilation Systems Work)

例如以上举例的 “Hello.c”简单C语言程序,我们需要依赖编译系统生成正确而且有效的机器码,所以这就是为什么程序员需要了解编译系统是如何工作的?

  • 优化程序性能。现代的编译器是复杂的工具而且会生成做正确的机器码。作为程序员,为了写出更有效率的代码我们不需要知道编译器具体的工作,但是需要基本清楚编译器是如何把C语言代码翻译成机器代码的。例如switch语句是否比if else语句更有效率?函数会产生多少开销? while循环是否比for循环更有效率?C指针是否比数组索引更有效率? 为什么在循环中我们使用引用参数调用的方式比直接在本地定义变量进行累加存储更慢呢?在一个函数中我们只是简单调整下算法表达式的括号就可以使其更有效率,这是为什么呢?
    在第三章,我们将会介绍x86(64位)的Linux,Mac和Windows系统的最新机器语言程序,我们会描述如何把C语言如何翻译成机器代码。在第五章,我们将会学习如何通过简单调整C语言代码就可以让编译器工作更快,从而提升程序性能。在第六章那你会学习内存的分层,C语言程序如何把数据存储到内存中,你可以利用这些知识使得你的C语言程序更有效率。

  • 读懂链接器的异常信息。在我们经验中,大部分程序错误都是跟链接器的操作有关,尤其是你在搭建大型软件系统的时候。链接器出现无法解决引用的异常的时候,这是什么情况?静态变量和全局变量的区别?当你定义了两个相同名称的全局变量将会发生什么?为什么我们列举引用库的顺序很重要?静态库和动态库的区别?为什么很多链接器关联的错误会出现在运行时?在第七章你会找到以上问题的答案。

  • 避免安全漏洞。这些多年来内存泄漏的问题是网络和互联网服务器中出现安全异常的主要原因。这些异常问题依然存在,是因为只有少数的程序员小心处理数量的限制,尤其是那些不受信任的数据来源。首先学习安全程序是知道任何一种数据来源的数据和控制那些在程序栈的信息。我们会在第三章通过汇编代码学习栈的规则和内存泄漏。我们也会学习通过编译器、操作系统来减少攻击威胁。

For simple programs such as hello.c , we can rely on the compilationsystem to produce correct and efficient machine code. However, there are some important reasons why programmers need to understandhow compilation systems work:

Optimizing program performance. Modern compilers are sophisticated tools that usually produce good code. As programmers, we do not need to know the inner workings of the compiler in order to write efficient code. However, in order to make good coding decisions in our C programs, we do need a basic understanding of machine-level code and how the compiler translates different C statements into machine code. For example,is a switch statement always more efficient than a sequence of if-else statements? How much overhead is incurred by a function call? Is a while loop more efficient than a for loop? Are pointer references more efficient than array indexes? Why does our loop run so much faster if we sum into a local variable instead of an argument that is passed by reference? How can a function run faster when we simply rearrange the parentheses in an arithmetic expression?

In Chapter 3 , we introduce x86-64, the machine language of recent generations of Linux, Macintosh, and Windows computers.We describe how compilers translate different C constructs into this language. In Chapter 5 , you will learn how to tune the performance of your C programs by making simple transformations to the C code that help the compiler do its job better. In Chapter6 , you will learn about the hierarchical nature of the memorysystem, how C compilers store data arrays in memory, and howyour C programs can exploit this knowledge to run more efficiently.

Understanding link-time errors. In our experience, some of the most perplexing programming errors are related to the operation of the linker, especially when you are trying to build large software systems. For example, what does it mean when the linker reports that it cannot resolve a reference? What is the difference between a static variable and a global variable? What happens if you define two global variables in different C files with the same name? What is the difference between a static library and a dynamic library? Why does it matter what order we list libraries on the command line? And scariest of all, why do some linker-related errors not appear until run time? You will learn the answers to these kinds of questions in Chapter 7 .

Avoiding security holes. For many years, buffer overflow vulnerabilities have accounted for many of the security holes in network and Internet servers. These vulnerabilities exist because too few programmers understand the need to carefully restrict the quantity and forms of data they accept from untrusted sources. A
first step in learning secure programming is to understand the consequences of the way data and control information are stored on the program stack. We cover the stack discipline and buffer overflow vulnerabilities in Chapter 3 as part of our study of assembly language. We will also learn about methods that can be
used by the programmer, compiler, and operating system to reduce the threat of attack.

## 软件功能详细介绍 1. **文本片段管理**:可以添加、编辑、删除常用文本片段,方便快速调用 2. **分组管理**:支持创建多个分组,不同类型的文本片段可以分类存储 3. **热键绑定**:为每个文本片段绑定自定义热键,实现一键粘贴 4. **窗口置顶**:支持窗口置顶功能,方便在其他应用程序上直接使用 5. **自动隐藏**:可以设置自动隐藏,减少桌面占用空间 6. **数据持久化**:所有配置和文本片段会自动保存,下次启动时自动加载 ## 软件使用技巧说明 1. **快速添加文本**:在文本输入框中输入内容后,点击"添加内容"按钮即可快速添加 2. **批量管理**:可以同时编辑多个文本片段,提高管理效率 3. **热键冲突处理**:如果设置的热键与系统或其他软件冲突,会自动提示 4. **分组切换**:使用分组按钮可以快速切换不同类别的文本片段 5. **文本格式化**:支持在文本片段中使用换行符和制表符等格式 ## 软件操作方法指南 1. **启动软件**:双击"大飞哥软件自习室——快捷粘贴工具.exe"文件即可启动 2. **添加文本片段**: - 在主界面的文本输入框中输入要保存的内容 - 点击"添加内容"按钮 - 在弹出的对话框中设置热键和分组 - 点击"确定"保存 3. **使用热键粘贴**: - 确保软件处于运行状态 - 在需要粘贴的位置按下设置的热键 - 文本片段会自动粘贴到当前位置 4. **编辑文本片段**: - 选中要编辑的文本片段 - 点击"编辑"按钮 - 修改内容或热键设置 - 点击"确定"保存修改 5. **删除文本片段**: - 选中要删除的文本片段 - 点击"删除"按钮 - 在确认对话框中点击"确定"即可删除
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值