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版)
函数
|
125
函数
swapf( a+i, a+mini); //
交换最小值元素和索引
i
元素的值
}
}
一般来说,不建议把将包含循环的函数定义成内联函数,例如函数
selection_
sortf()
。例
7-7
在
for
循环中使用内联函数来加速执行效率。
inline
修饰符并非强制性的:编译器有可能会置之不理。例如,递归函数通常不会被编
译成内联函数。编译器有权自行决定是否要将有
inline
修饰符的函数编译成内联函数。
和其他函数不同的是,在每个用到内联函数的翻译单元中,都必须重复定义这个内联函
数。编译器必须时刻准备好该函数定义,以便在调用它时及时插入内联代码。因此,经
常在头文件中定义内联函数。
如果某个翻译单元内的某个函数的所有声明都具有
inline
修饰符,而没有
extern
修饰
符,那么该函数具有内联定义(
inline definition
)。内联定义只针对翻译单元,它不构
成外部定义,因此别的翻译单元可以包含该函数的外部定义。如果有外部定义附加到内
联定义中,那么编译器可以自由选择要使用哪一种定义。
如果使用存储类修饰符
extern
来声明一个采用
inline
定义的函数,那么该函数的定义就
会是外部的(
external
)。例如,下面的声明与
swapf()
的定义如果放在例
7-7
的同一个翻
译单元中,那么
swapf()
就具有
extern
定义:
extern void swapf( float *p1, float *p2 );
一旦函数
swapf()
具有外部的定义,其他翻译单元只需要采用普通的函数声明,就可以 ...
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