Guard against #including new and old version in the same file #3337
mortenfyhn
started this conversation in
Ideas
Replies: 1 comment 4 replies
-
As the include guard is undefined at the end of the |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I recently had a case where we included this library (v3.9.1) and unexpectedly got a bunch of redefinition errors. After some digging, it turned out we indirectly included a much older version of this library (v2.1.1), which was being used internally in some header. These
versions use different header guards, so the double inclusion wasn't avoided that way.
The old guard is
NLOHMANN_JSON_HPP
and the new one isINCLUDE_NLOHMANN_JSON_HPP_
.What about checking for
#ifdef NLOHMANN_JSON_HPP
, and if true, show a warning (with#warning
maybe)? That way the developer will quickly realize what's going on.I suppose that will only help if you include the new version after the old version, but it seems better than nothing.
Beta Was this translation helpful? Give feedback.
All reactions