MikeLankamp / fpm

C++ header-only fixed-point math library
https://mikelankamp.github.io/fpm
MIT License
673 stars 85 forks source link

Unable to compile when minwindef.h is (implicitly) included before fixed.hpp #41

Closed Cerclique closed 2 years ago

Cerclique commented 2 years ago

Window's header minwindef.h define the macro min() and max().

When this file is included before fixed.hpp, this fail to compile because min/max method of numeric_limit<fixed> are refering to the windows macro as showed in the screenshot below.

screenshot

I did not look that much into the subject but it seems to be a reccurent problem for libraries that are using min/max methods and are co-existing with the windows header in an application.

The solution I use for now is the include fixed.hpp before the header that include minwindef.h.

I think, this information might be worth to be included as a note in the documentation or somewhere else.

MikeLankamp commented 2 years ago

Yes, this is a known problem with the Windows headers. Honestly, I think this a problem with the Windows SDK and not worth noting in every possible project that uses standard-compliant C++.

Note that you can #define NOMINMAX before including any Windows headers to fix this without relying on include order. Will that solve this issue for you as well?

Cerclique commented 2 years ago

Yes, you are totally right.

I just noticed that I forgot to mention NOMINMAX as well that, indeed, also solve the issue.