Skip to Content
C语言核心技术(原书第2版)
book

C语言核心技术(原书第2版)

by Peter Prinz, Tony Crawford
August 2017
Intermediate to advanced
798 pages
17h 44m
Chinese
China Machine Press
Content preview from C语言核心技术(原书第2版)
标准头
|
277
标准头
•
在所包含的头文件中定义的所有宏标识符,都是被保留的。
•
在标准头文件中被声明为文件的标识符,在它们自身命名空间范围内,是被保留
的。一旦在源文件中包含一个头文件,在同一个命名空间中,不能将在该头文件中
声明为文件的标识符用作其他目的,或作为宏名称(请参见
1.6.1
节)。
虽然这里所列出的一些条件有“漏洞”,允许在某些命名空间或配合静态链接重复使用
某些标识符,但是标识符过多重用很容易造成混淆,通常最安全的方式是完全规避标准
头文件中的标识符。在下面的各节中,为了未来
C
标准的扩充,我们也会列出一些被保
留的标识符。前面列表中的最后三点也适用于这些保留的标识符。
16.2 边界检查函数
在
C
标准库中的许多传统函数,它们将字符串复制给数组,这些数组由程序员通过指针
参数提供。没有办法为这些函数测试给定的目标数组是否足以容纳结果。程序员自己需
要负责以确保没有数据在写入时超出数组边界,否则可能会修改内存中与数组相邻位置
的对象。这对程序的可靠性和安全性而言,是一个重要威胁,可能导致程序崩溃。
为了缓解这一问题,
C11
标准中的附录
K
引入了许多新函数,它们可作为传统标准
C
函数
在考虑安全性方面的额外选择。这些替代函数也称为安全函数,采取额外参数来指定目
标数组大小。该安全函数使用该信息,以确保它们生成的结果不会超过数组边界。安全
函数名称均有后缀
_s
(
s
意为“安全”(
secure
)),例如
strcpy_s()
。
不同于传统函数
strcpy()
,函数
strcpy_s()
只
在指定的目标数组足以容纳待复制字符串的条件下,才执 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

算法精讲视频课程:24篇系列讲座

算法精讲视频课程:24篇系列讲座

罗伯特·塞奇威克, 凯文·韦恩(Kevin Wayne)

Publisher Resources

ISBN: 9787111562207