Go Down

Topic: Mark macros in documentation (Read 424 times) previous topic - next topic


Arduino is a beginner-IDE afterall. Macros like constrain() can stump beginners. If you use constrain in a way similar to this:
Code: [Select]
// read values from eeprom and constrain to allowed range
int address = 0;
uint8_t value = constrain(EEPROM.read(address++), 23, 99);

It will no give the desired results because the expression is expanded to:
Code: [Select]
uint8_t value = EEPROM.read(address++) < 23 ? 23 : EEPROM.read(address++) > 99 ? 99 : EEPROM.read(address++);
I suggest a short note ala "This is a macro function. See here for possible pitfalls when using macros.", linking to a short Macro topic (like #define which should also link there) that explains the above issue.

Best Regards,

Go Up