博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ObjC宏定义小细节
阅读量:7174 次
发布时间:2019-06-29

本文共 753 字,大约阅读时间需要 2 分钟。

Macros

A definition that takes arguments, particularly more than one, is often known as a macro:

#define SQUARE(x) x * x

Incidentally, the previous definition leads to an interesting problem. What would happen with this line:

y = SQUARE(v + 1);

Because of the literal substitution, what actually gets compiled is y = v + 1 * v + 1;, which algebraically simplifies to y = 2 * v + 1;. Therefore, the macro should be properly define as

#define SQUARE(x) ( (x) * (x) )

Therefore, y = SQUARE(v + 1); becomes y = ( (v + 1) * (v + 1) );.

The rule of thumb is to enclose each argument within the definition in parentheses, which should avoid the issue above.

原来宏定义的时候,会发生这种情况。。。以后定义宏四则运算的时候要注意运算优先级了。

原文地址:

转载于:https://www.cnblogs.com/kptanjunhao/p/5644337.html

你可能感兴趣的文章
模块打包
查看>>
lombok的使用和原理
查看>>
浏览器异步队列执行优先级
查看>>
maven web project in intellij
查看>>
OSChina 娱乐弹弹弹——将程序猿表白方式进行到底!
查看>>
OSChina 周四乱弹 —— 人生处处是深坑
查看>>
OSChina 周日乱弹 —— 如何处理学生早恋
查看>>
OSChina 周日乱弹 ——什么姑娘是女!王!大!人!
查看>>
OSChina 周二乱弹 —— 以后我偷小鱼干养你
查看>>
Limu:JavaScript的那些书
查看>>
自定义线程---无界队列作为承装任务
查看>>
Scala 学习笔记
查看>>
Ipython的 Debug 函数
查看>>
基于虹软sdk,java实现人脸识别(demo)
查看>>
Android模拟器入门
查看>>
ZOJ_1094/hdoj_1082_Matrix Chain Multiplication_...
查看>>
1040_As easy as A+B
查看>>
java8如何反射得到方法参数变量的名字
查看>>
Spring Data Redis 让 NoSQL 快如闪电 (1)
查看>>
git库detached heads问题处理
查看>>