简体   繁体   中英

Macro arguments HEX and DEC

According to that guide: enter link description here

i wrote:

#define DEBUG
#ifdef DEBUG
 #define DEBUG_PRINT(x)  Serial.print (x)
 #define DEBUG_PRINTLN(x)  Serial.println (x)
 #define DEBUG_PRINT_HEX(x)  Serial.print (x, HEX)
 #define DEBUG_PRINT_DEC(x)  Serial.print (x, DEC)
#else
 #define DEBUG_PRINT(x)
 #define DEBUG_PRINTLN(x)
 #define DEBUG_PRINT_HEX(x)
 #define DEBUG_PRINT_DEC(x)
#endif

if i call a function:

uint32_t versiondata;
DEBUG_PRINT_HEX((versiondata>>24) & 0xFF, HEX);
DEBUG_PRINT_DEC((versiondata>>16) & 0xFF, DEC);
uint8_t uidLength;
DEBUG_PRINT_DEC(uidLength, DEC);

the compiler give me:

error: macro "DEBUG_PRINT_DEC" passed 2 arguments, but takes just 1
error: macro "DEBUG_PRINT_HEX" passed 2 arguments, but takes just 1

Someone can explain me why does not works?

Look at the error message. You had defined this macro:

#define DEBUG_PRINT_HEX(x)

This macro want one argument: the x

And you call the macro with two arguments:

DEBUG_PRINT_HEX((versiondata>>24) & 0xFF, HEX);  

1 argument: (versiondata>>24) & 0xFF

2 argument: HEX

Just call the macro like this:

DEBUG_PRINT_HEX((versiondata>>24) & 0xFF);  

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