简体   繁体   中英

Need help understanding lowByte and highByte

I'm a beginner with C++ and I'd like to decipher some code:

    #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)) .

This step is performed by the preprocessor prior to compilation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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