-
Notifications
You must be signed in to change notification settings - Fork 34
max() macro does not play well with std::max() #165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
An alternative would be to use a template function rather than a macro, at least in C++. For C, this won't work and you'll still need to macro, but in C (lacking namespaces, overloading and methods) this is not so likely to be problematic. This was already applied in the ArduinoCore-API repo, so that's probably easy to just copy: https://github.com/arduino/ArduinoCore-API/blob/45e4e5aba6ad1a5b67026b686099cc0fce437cdc/api/Common.h#L120-L147 Actually, this is partly a duplicate of #133, and I just realized I already provided a fix for this in #144. Maybe you could test that and see if it helps? |
Using the alternative macro gives a similar error. Essentially it translates
into
Which still gives |
But the code in my PR applies the alternative macro only for C code, for c++ code it uses a template function? |
Yes, I see that now. I've updated my code using this approach and it now passes the tests. I'll close this as a duplicate of #133. |
I said that I updated my code but this keeps happening and I don't remember what I changed. Well, it is in LiquidCrystal_CI.h. |
If I include
<Arduino.h>
before<vector>
, then I get an error instl_vector.h:1645
where the code refers to std::max().This appears to be due to a macro definition of
max()
inarduino_ci-0.3.0/cpp/arduino/AvrMath.h
causing the code to be expanded to:This produces
error: expected unqualified-id before ‘(’ token
(which makes sense).My research suggests that this sort of use of macros should be avoided.
But I need to do the includes in this order. If I include them in the other order then I get an error that
<vector>
isn't available in the Arduino compile (I have a check forMOCK_PINS_COUNT
to leave out non-test code in the Arduino compiles).The workaround is to
#undef max
(see line 6).The text was updated successfully, but these errors were encountered: