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版)
124
|
第
7
章
if ( pNode != NULL )
initNode( pNode );
return pNode;
}
如果无法为新的
Node
对象分配存储空间,则函数
mkNode()
会返回一个空指针。返回指针
的函数通常采用返回空指针来表示失败。例如,一个搜索函数,如果找到了满足条件的
对象,则返回该对象的地址,如果没有找到满足条件的对象,则返回空指针。
7.5 内联函数
一般来说,调用一个函数流程为:当前调用命令的地址被保存下来,程序流跳转到所调
用的函数并执行该函数,最后跳转回之前所保存的命令地址。对于需要经常调用的小函
数来说,这大大降低了程序运行效率。所以,
C99
新增了内联函数(
inline function
)。
关键字
inline
告诉编译器,任何地方只要调用内联函数,就直接把该函数的机器码插入
到调用它的地方。这样程序执行更有效率,就好像将内联函数中的语句直接插入到了源
代码文件中需要调用该函数的地方一样。
要将一个函数定义为内联函数,需要在函数定义时加上
inline
函数修饰符。例
7-7
中,
swapf()
被定义为内联函数,用来交换两个浮点变量的值,函数
selection_sortf()
会调
用内联函数
swapf()
。
例
7-7
:函数
swapf()
//
函数
swapf()
交换两个浮点变量的值
//
参数:两个指向
float
的指针
//
返回值:无
inline void swapf( float *p1, float *p2 ) //
一个内联函数
{
float tmp = ...
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