Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我是 C++ 的初学者,我想破译一些代码:
#define lowByte(w) ((uint8_t) ((w) & 0xff)) #define highByte(w) ((uint8_t) ((w) >> 8))
它看起来像变量声明,但我以前从未见过这种语法。有人可以分解这两行并告诉我它们的意思吗?
这些是宏声明。
每当您lowByte(0x1234)的代码中有,它将被宏的右侧部分替换,用它们的值替换参数,即((uint8_t) ((0x1234) & 0xff)).
lowByte(0x1234)
((uint8_t) ((0x1234) & 0xff))
此步骤由预处理器在编译之前执行。