arduino/ArduinoCore-avr

Arduino.h Defines Macros that Should be Functions

moefrumkin opened this issue · 1 comments

#define min(a,b) ((a)<(b)?(a):(b))

This macro and those that follow will lead to unexpected behavior if certain expressions are passed into it. For example,

    int x = 0, y = 1;
    
    printf("Min is: %d", min(++x, ++y));

Will print 2 instead of 1 since the expansion gives the expression ((++x)<(++y)?(++x):(++y)). Is there a reason this shouldn't be a function?

Hi @moefrumkin. Thanks for taking the time to submit an issue.

I see we have another report about this at #324.

It is best to have only a single issue per subject so we can consolidate all relevant discussion to one place, so I'll go ahead and close this in favor of the other.