当前位置:网站首页>C陷阱与缺陷 第6章 预处理器 6.1 不能忽视宏定义中的空格
C陷阱与缺陷 第6章 预处理器 6.1 不能忽视宏定义中的空格
2022-07-30 17:10:00 【weixin_客子光阴】
不能忽视宏定义中的空格
一个宏如果不带参数,则只需要使用宏名即可,括号无关紧要。预处理器从宏定义中就可以知道宏调用时是否需要参数。
与宏调用相比,宏定义显得有些“暗藏机关”。例如,下面的宏定义中f是否带了一个参数呢?
#define f (x) ((x) - 1)
答案只可能有两种:f(x)或者代表
((x) - 1)
或者代表
(x) ((x) - 1)
第二个答案是正确的,因为在f和后面的(x)之间多了一个空格!所以,如果希望定义f(x)为((x)-1),
必须像下面这样写:
#define f(x) ((x) - 1)
这一规则不适用于宏调用,而只适用于宏定义。因此,在上面完成宏定义后,f(3)与f (3)求值后都等于2。
边栏推荐
猜你喜欢

Research on intelligent charging strategy of matlab simulink lithium-ion battery

ERROR 2003 (HY000) Can‘t connect to MySQL server on ‘localhost3306‘ (10061)解决办法

.NET 6.0中使用Identity框架实现JWT身份认证与授权

Weka 3.8.6安装与Weka 3.8.6功能介绍

你是这样的volatile,出乎意料

Win11如何把d盘空间分给c盘?Win11d盘分盘出来给c盘的方法

The first time I used debug query and found that this was empty, does it mean that the database has not been obtained yet?please help.

【AAAI2020】阿里DMR:融合Matching思想的深度排序模型

链表Oj练习题 纯C语言

Explore CSAPP Experiment 2-bomb lab-Section 1
随机推荐
What does a good resume look like in the eyes of a big factory interviewer?
阿里SIM-基于检索的用户行为兴趣CTR模型(Search-based user Interest Model(SIM))
Analysis and Simulation of Short Circuit Fault in Power System Based on MATLAB
Lotus 1.16.0 minimum snapshot export import
Microsoft Office 2019 software download and installation detailed tutorial!
万华化学精细化工创新产品大会
Error occurred while trying to proxy request项目突然起不来了
Google Cloud Spanner的实践经验
腾讯专家献上技术干货,带你一览腾讯广告召回系统的演进
理解实现搜索二叉树
OpenCV形状检测
Daily practice------Generate 13-digit bar, Ean-13 code rule: The thirteenth digit is the check code obtained by the calculation of the first twelve digits.
MySQL详细学习教程(建议收藏)
How does the new retail saas applet explore the way to break the digital store?
fast shell porting
Valid bracketed strings [greedy exercise]
Chapter 5 Advanced SQL Processing
LeetCode167:有序数组两数之和
全球架构师峰会
Chapter 6: Decisive Autumn Moves