Skip to content
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

Much easier fix for min vs std::min issue #1785

Open
dberlin opened this issue Aug 3, 2022 · 3 comments
Open

Much easier fix for min vs std::min issue #1785

dberlin opened this issue Aug 3, 2022 · 3 comments

Comments

@dberlin
Copy link

dberlin commented Aug 3, 2022

(It's not obvious where the website docs live in github, or i'd just submit a pull request)
The troubleshooter for the std::min vs arduino min macro (https://arduinojson.org/v6/troubleshooter/?utm_source=github&utm_medium=readme#compiletime/macro-min/success) says to disable std::string/std::stream support.

Just to flag there is actually a much easier fix that does not require compiler flags and should work everywhere.

Before including ArduinoJson.h, do this:

#include <Arduino.h>
#undef min

min is guaranteed to be defined in C++ so we don't have to worry that we will remove the only definition (it's also supposed to be an inline function and not a macro, which is why it conflicts in the first place)

Including the header ourselves guarantees that all the macros are defined and that the header won't be reincluded by someone else.
#undef min then removes the conflicting macro definition.
This will work:

  1. On all systems where someone uses ArduinoJSON
  2. whether the min macro exists or not.
  3. without removing support for std::*

Figured i would flag this.

@dberlin dberlin changed the title Much easier fix for min vs std::min isse Much easier fix for min vs std::min issue Aug 3, 2022
@bblanchon
Copy link
Owner

Hi @dberlin,

Thank you for this feedback.

The source of the website is, indeed, in a private repo.

Is it sufficient to #undef min? or do we also need to #undef max?

Best regards,
Benoit

@dberlin
Copy link
Author

dberlin commented Oct 11, 2022 via email

@bblanchon
Copy link
Owner

ArduinoJson doesn't use min either, but the STL uses it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants