Multi-line DEFINE directives?(多行 DEFINE 指令?)
问题描述
我不是专家,所以请放轻松.这两个代码段有什么区别吗?
I am not an expert, so go easy on me. Are there any differences between these two code segments?
#define BIT3 (0x1
<
<
3)
static int a;
和
#define BIT3 (0x1 << 3) static int a;
另外,有没有办法在一行中写第一个?这种多线样式的意义何在?下面的代码好吗?
Also, is there a way to write the first in one line? What is the point of this multi-line style? Is the following code good?
#define BIT3 (0x1 << 3)
static int a;
推荐答案
如果您有一个非常复杂的宏,如果它全部在一行上将难以阅读(尽管不建议使用多行宏)非常复杂的宏).
A multi-line macro is useful if you have a very complex macro which would be difficult to read if it were all on one line (although it's inadvisable to have very complex macros).
一般来说,您可以使用续行字符 编写多行定义.所以例如
In general, you can write a multi-line define using the line-continuation character, . So e.g.
#define MY_MACRO printf(
"I like %d types of cheese
",
5
)
但是你不能在你的第一个例子中做到这一点.你不能像那样拆分令牌;<< 左移运算符必须始终在没有任何分隔空格的情况下编写,否则它将被解释为两个小于运算符.所以也许:
But you cannot do that with your first example. You cannot split tokens like that; the << left-shift operator must always be written without any separating whitespace, otherwise it would be interpreted as two less-than operators. So maybe:
#define BIT3 (0x1
<<
3)
static int a;
现在相当于你的第二个例子.
which is now equivalent to your second example.
[虽然我不确定那个宏会有什么用处!]
这篇关于多行 DEFINE 指令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:多行 DEFINE 指令?
基础教程推荐
- c++ STL设置差异 2022-01-01
- C++:获取传递给函数的多维数组的行大小 2021-01-01
- 为什么我们不能使用“虚拟继承"?在 COM 中? 2022-01-01
- 将不可复制的闭包对象传递给 std::function 参数 2021-01-01
- 随机插入/删除的综合向量与链表基准 2022-01-01
- 如何在 C++ 中正确使用命名空间? 2022-01-01
- 如何部分禁用 cmake C/C++ 自定义编译器检查 2021-01-01
- 如何更改 SysDateTimePick32 或 CDateTimeCtrl 的背景颜色? 2022-01-01
- 与 CAS 的原子交换(使用 gcc 同步内置函数) 2022-01-01
- 提升 ASIO 流缓冲 2021-01-01
