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版)
264
|
第
15
章
型为
double
或整数的实参
arg
调用该宏,该泛型选择的结果是默认表达式,因此,宏最
终调用结果为表达式
log10(
arg
)
。
15.4 条件式编译
条件式编译(
conditional compiling
)命令指定预处理器依据特定的条件来判断保留或删
除某段源代码。例如,可以使用条件式编译让源代码适用于不同的目标系统,而不需要
管理该源代码的各种不同版本。
条件式编译区域以
#if
、
#ifdef
或
#ifndef
等命令作为开头,以
#endif
命令结尾。条件式
编译区域可以有任意数量的
#elif
命令,但最多一个
#else
命令。以
#if
开头的条件式编
译区域具有下面的格式:
#if
表达式
1
[
组
1
]
[#elif
表达式
2
[
组
2
]]
...
[#elif
表达式
n
[
组
n
]]
[#else
[
组
n+1
]]
#endif
预处理器会依次计算条件表达式,直到发现结果非
0
(也就是
true
)的条件表达式。预
处理器会保留对应组内的源代码,以供后续处理。如果找不到值为
true
的表达式,并且
该条件式编译区域中包含
#else
命令,则保留
#else
命令组内的代码。
组
1
、
组
2
等代码段,可以包含任意
C
源代码,也可以包含更多的命令,包括嵌套的条件
式编译命令。在预处理阶段结束时,没有被预处理器保留以用于后续处理的组会从程序
中全部删除。
15.4.1 #if和#elif命令
作为
#if
或
#elif
命令条件的表达式,必须是整数常量预处理器表达式。这与普通的整数
常量表达式不同(请参见
5.3
节),主要区别在于: ...
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