cginternals / libzeug

deprecated: C++ sanctuary for small but powerful and frequently required, stand alone features.
MIT License
16 stars 13 forks source link

Resolve conflict with windef.h macros and remove implicit cast #42

Closed philippotto closed 10 years ago

philippotto commented 10 years ago

As soon as windef.h is included in a project (or another file which defines the max-macro), the existing calls to std::numeric_limits::max won't compile. I added defensive parenthesis to resolve this conflict.

mjendruk commented 10 years ago

We had a similar problem in our Game Programming project and we solved it by defining NOMINMAX in CMakeLists.txt with add_definitions("-DNOMINMAX"). Have you tried this?

sbusch42 commented 10 years ago

I see a few possible solutions:

But in general, system specific headers should not be included at all in a way that is spreads through the whole project. Include system specific headers only when needed, in the closest scope possible, e.g., only inside one .cpp file where you really need to make system specific implementations. Never in a header.

Even more general, avoid system specific headers at all. When using Qt you have a great cross-platform-basis, it's a shame to throw that away by unnecessary use of system specific functionality ;)

Regarding this issue: It's not a problem in our lib, and we shouldn't begin to make fixes or workarounds for problem coming from other libraries and/or operating systems. In Windows, it's min/max, with XLib, things like None or Window are defined, then we have to change our classes again to avoid those names. The bug is inside those other libraries making use of macros where they shouldn't, we can't and shouldn't introduce workarounds for them in our code.

philippotto commented 10 years ago

I thought that a few parenthesis wouldn't hurt, but now I agree on the fact that we shouldn't start to handle problems which are caused by third parties. After having refactored our integration of scriptzeug, the conflict was solved automatically. Thanks for your suggestions. And I am glad to see, that the removal of the implicit cast made it into the master.