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版)
预处理命令
|
263
预处理命令
15.2.4 宏的作用域和重新定义
你无法再次使用
#define
命令重新定义一个已经被定义为宏的标识符,除非重新定义所使
用的替换文本与已经被定义的替换文本完全相同。如果该宏具有形参,重新定义的形参
名称也必须与已定义形参名称的一样。
如果想改变一个宏的内容,必须首先使用下面的命令取消现在的定义:
#undef
宏名称
执行上面的命令之后,标识符“宏名称”可以再次在新的宏定义中使用。如果上面指定
的标识符并非一个已定义的宏名称,那么预处理器会忽略这个
#undef
命令。
标准库中的多个函数名称也被定义成了宏。如果想直接调用这些函数,而不是调用同名
称的宏,可以使用
#undef
命
令取消对这些宏的定义。即使准备取消定义的宏是带有参数
的,也不需要在
#undef
命令中指定参数列表。如下例所示:
#include <ctype.h>
#undef isdigit //
移除任何使用该名称的宏定义
/* ... */
if ( isdigit(c) ) //
调用函数
isdigit()
/* ... */
当某个宏首次遇到它的
#undef
命令时,它的作用域就会结束。如果没有关于该宏的
#undef
命令,那么它的作用域在该翻译单元结束时终止。
15.3 泛型宏
C11
标准新增了泛型选择(
generic selection
),它的作用类似于针对数据类型的
switch
语句。泛型选择等效于依据一个表达式的类型,从一个备选的列表中选出另一个表达式
(详细信息请参见
5.1.1
节)。这意味着,程序员可以定义自己的泛型宏,如同 ...
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