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版)
253
第15章
预处理命令
在
1.7
节,我们概述了从
C
源代码到可执行文件之间的
8
个编译步骤。在前
4
个步骤中,
C
预处理器会为编译器准备好源代码。预处理器处理获得结果是修改过的源代码,注释被
删除,并且预处理命令(
preprocessing directive
)也被它们自身的执行结果所取代。
本章讨论
C
语言的预处理命令。这些命令可以将别的源代码内容插入到所指定的位置;
可以标识出只有在特定条件下才会被编译的某一段程序代码;可以定义类似标识符功能
的宏,在编译时,预处理器会用别的文本取代该宏。
每个预处理命令均独占一行,以
#
字符作为开头。只有空格符(
space
)和制表符(
tab
)
可以出现在
#
字符的前面。命令在遇到本行的第一个换行符时结束。最短的预处理命令
是空命令(
null directive
)。该命令整行只有一个
#
,可能还伴随一些注释或空白符。空
命令不起任何作用:预处理器会直接将它们从源代码中删除。
命令可以跨行,可以在行尾放置一个反斜线
(\)
,并且在下一行继续上一行未完的命
令。如下例所示:
#define MacroName A long, \
long macro replacement value
这个反斜线必须是换行符前的最后一个字符。预处理器会直接删除反斜线和换行符,并
把两行命令连接成一行。因为预处理器也会把每个注释使用空格来代替,所以如果在反
斜线和换行字符之间放置注释,那么这样的反斜线就不具有跨行作用。
空格符和制表符可以出现在
#
字符与命令名称之间。(在上述示例中,命令名称是
define
。)
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