简体   繁体   中英

How to read out a #define macro in C?

I am unexperienced in C and have a question. I wanted to ask how to read the hexadecimal numbers out and get into an array

#define configMAC_ADDR                \
{                                      \
    0x02, 0x12, 0x13, 0x10, 0x15, 0x11  \
}

The macro is the same as writing { 0x02, 0x12, 0x13, 0x10, 0x15, 0x11 } . So where you would have normally written that initializer list in your source code, write configMAC_ADDR instead. It's just text replacement in this case.


The \\ symbol can appear anywhere in C code and means source code line break. You can use it to break up a long line of code into several and have the compiler treat them as a single line still, so it is commonly used for macros. Without it you'd have to write the macro as:

#define configMAC_ADDR { 0x02, 0x12, 0x13, 0x10, 0x15, 0x11 }

Which is 100% equivalent but in some cases less readable.

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