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版)
126
|
第
7
章
器会进一步优化代码:当调用无返回函数时,不需要将返回地址或
CPU
寄存器内容推送
到栈中。如果在无返回函数调用后的语句块中还存在其他命令,则编译器也会发出一个
“
unreachable code
”(执行不到的代码)的警告。
下例展示了一个用户定义函数,它不返回:
_Noreturn void myAbort()
{
/* ...
清理与保存数据等相关命令
... */
abort();
}
值得注意的是,必须是在绝对不会返回的情况下,才能采用
_Noreturn
声明一个函数。
如果一个采用
_Noreturn
声明的函数返回了,则程序的行为是不确定的,根据标准要
求,编译器会发出一个诊断信息。
如果程序包含了头文件
stdnoreturn.h
,也可以使用同义词
noreturn
替代关键字
_Noreturn
。
7.7 递归函数
递归(
recursive
)函数是“自己调用自己”的函数,无论是采用直接或间接调用方式。
间接递归意味着函数调用另一个函数(然后可能又调用第三个函数等),最后又调用第
一个函数。因为函数不可以一直不停地调用自己,所以递归函数一定具备结束条件。
在例
7-8
中,递归函数
binarySearch()
实现二元搜索算法,在排序好的数组中找到特定
元素。首先,该函数根据搜索条件比较数组最中间的元素。如果相同,就返问该元素的
指针,表示找到了;如果不相同,该函数会调用自己,在可能存在满足搜索条件的一半
数组中搜索,一直递归地进行下去,指导找到满足搜索条件的元素。如果剩下数组的长
度为
0
,则表示找不到,那么递归就会结束。 ...
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