From 90a5b2f89b27945bcc2d12159bfa72f9fe522b5a Mon Sep 17 00:00:00 2001 From: Nyq <623434+nyq@users.noreply.github.com> Date: Tue, 15 Aug 2023 07:21:03 -0400 Subject: [PATCH] Prevent min/max conflicts between windows.h and std namespace Miniz started including windows.h from version 3.0.0 and on when compiling for Windows using MSVC. windows.h header file is known to conflict with C++ std namespace by defining its own min/max macros. It is a common practice to disable these ancient macros in windows.h by declaring NOMINMAX macro prior to including windows.h in code. While this issue does not affect miniz directly due to the fact that it is straight-C code and it does not use min/max from C++ std namespace, it does affect other projects like miniz-cpp which wrap and amalgamate miniz and then both compile in C++ mode and use min/max from std namespace. It is therefore proposed to prefix inclusion of windows.h in miniz_zip.c by the following lines: #ifndef NOMINMAX #define NOMINMAX #endif --- miniz_zip.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/miniz_zip.c b/miniz_zip.c index 5fe8ddf..c58b39e 100644 --- a/miniz_zip.c +++ b/miniz_zip.c @@ -43,7 +43,10 @@ extern "C" { #define WIN32_LEAN_AND_MEAN #ifndef __cplusplus -#define MICROSOFT_WINDOWS_WINBASE_H_DEFINE_INTERLOCKED_CPLUSPLUS_OVERLOADS 0 + #define MICROSOFT_WINDOWS_WINBASE_H_DEFINE_INTERLOCKED_CPLUSPLUS_OVERLOADS 0 +#endif +#ifndef NOMINMAX + #define NOMINMAX #endif #include