简体   繁体   English

需要帮助了解lowByte和highByte

[英]Need help understanding lowByte and highByte

I'm a beginner with C++ and I'd like to decipher some code: 我是C ++的初学者,我想破译一些代码:

    #define lowByte(w) ((uint8_t) ((w) & 0xff))
    #define highByte(w) ((uint8_t) ((w) >> 8))

It looks like variable declaration but I've never seen this syntax before. 它看起来像变量声明,但我之前从未见过这种语法。 Can someone break these two lines down and tell me what they mean? 有人可以分解这两行并告诉我这是什么意思吗?

Those are macros declarations. 这些是声明。

Whenever you have lowByte(0x1234) in your code, it will be replaced with the right part of the macro, substituting arguments with their values, that is ((uint8_t) ((0x1234) & 0xff)) . 每当您的代码中有lowByte(0x1234)时,它将被宏的右侧部分替换,并用其值替换参数((uint8_t) ((0x1234) & 0xff))

This step is performed by the preprocessor prior to compilation. 编译之前,此步骤由预处理器执行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM