Skip to content

Resolve macro conflicts in Windows#1495

Merged
marty-johnson59 merged 1 commit intoKhronosGroup:mainfrom
Stellarist:fix_windows_macro_conflict
Mar 9, 2026
Merged

Resolve macro conflicts in Windows#1495
marty-johnson59 merged 1 commit intoKhronosGroup:mainfrom
Stellarist:fix_windows_macro_conflict

Conversation

@Stellarist
Copy link
Copy Markdown

@Stellarist Stellarist commented Mar 1, 2026

Description

This PR addresses two problems related to Windows macro conflicts:

  • max/min definition
    Changed the check from if(MSVC) to if(WIN32) when defining NOMINMAX. This ensures that the min/max macros from <windows.h> are masked on all Windows compilers (MSVC, clang-cl, MinGW).

  • #ifdef checks in source
    Replaced #if WIN32 with #ifdef WIN32 to ensure correct macro detection. This avoids potential compilation errors when building with Clang + MSVC, where undefined macros could cause preprocessing issues.

General Checklist:

Please ensure the following points are checked:

  • [√] My code follows the coding style
  • [√] I have reviewed file licenses
  • [ ] I have commented any added functions (in line with Doxygen)
  • [ ] I have commented any code that could be hard to understand
  • [√] My changes do not add any new compiler warnings
  • [√] My changes do not add any new validation layer errors or warnings
  • [√] I have used existing framework/helper functions where possible
  • [√] My changes do not add any regressions
  • [√] I have tested every sample to ensure everything runs correctly
  • [√] This PR describes the scope and expected impact of the changes I am making

Note: The Samples CI runs a number of checks including:

  • [ ] I have updated the header Copyright to reflect the current year (CI build will fail if Copyright is out of date)
  • [√] My changes build on Windows, Linux, macOS and Android. Otherwise I have documented any exceptions

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 1, 2026

CLA assistant check
All committers have signed the CLA.

@Stellarist Stellarist marked this pull request as ready for review March 1, 2026 14:58
@Stellarist Stellarist force-pushed the fix_windows_macro_conflict branch 2 times, most recently from 5837cfe to 1775a8e Compare March 3, 2026 13:08
@asuessenbach
Copy link
Copy Markdown
Contributor

Under what circumstances do you encounter that problem? I don't see any issues on Win11.

@Stellarist
Copy link
Copy Markdown
Author

Under what circumstances do you encounter that problem? I don't see any issues on Win11.

Compiler
Clang 22.1 + MSVC 18.3.2

System
Windows 11 Pro 22H2
Windows SDK 10.0.26100.0

Errors
[build] C:/Data/repos/samples_vk/framework\common/helpers.h:205:96: error: too few arguments provided to function-like macro invocation
[build] 205 | if (static_cast<uintmax_t>(value) > static_cast<uintmax_t>(std::numeric_limits<uint32_t>::max()))
[build] | ^
[build] C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\shared\minwindef.h:193:9: note: macro 'max' defined here
[build] 193 | #define max(a,b) (((a) > (b)) ? (a) : (b))
[build] | ^
[build] In file included from C:/Data/repos/samples_vk/framework/core/debug.cpp:20:
[build] In file included from C:/Data/repos/samples_vk/framework\core/command_buffer.h:22:
[build] In file included from C:/Data/repos/samples_vk/framework\core/device.h:22:
[build] In file included from C:/Data/repos/samples_vk/framework\core/buffer.h:23:
[build] In file included from C:/Data/repos/samples_vk/framework\core/allocated.h:23:
[build] In file included from C:/Data/repos/samples_vk/framework\core/physical_device.h:21:
[build] In file included from C:/Data/repos/samples_vk/framework\core/instance.h:21:
[build] C:/Data/repos/samples_vk/framework\common/helpers.h:205:38: error: static_cast from 'unsigned int (*)() noexcept' to 'uintmax_t' (aka 'unsigned long long') is not allowed
[build] 205 | if (static_cast<uintmax_t>(value) > static_cast<uintmax_t>(std::numeric_limits<uint32_t>::max()))
[build] | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[build] In file included from C:/Data/repos/samples_vk/framework/core/debug.cpp:20:
[build] In file included from C:/Data/repos/samples_vk/framework\core/command_buffer.h:22:
[build] In file included from C:/Data/repos/samples_vk/framework\core/device.h:25:
[build] In file included from C:/Data/repos/samples_vk/framework\hpp_fence_pool.h:20:
[build] C:/Data/repos/samples_vk/framework\fence_pool.h:48:70: error: too few arguments provided to function-like macro invocation
[build] 48 | VkResult wait(uint64_t timeout = std::numeric_limits<uint64_t>::max()) const;
[build] | ^
[build] C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\shared\minwindef.h:193:9: note: macro 'max' defined here
[build] 193 | #define max(a,b) (((a) > (b)) ? (a) : (b))
[build] | ^
[build] In file included from C:/Data/repos/samples_vk/framework/core/debug.cpp:20:
[build] In file included from C:/Data/repos/samples_vk/framework\core/command_buffer.h:22:
[build] In file included from C:/Data/repos/samples_vk/framework\core/device.h:25:
[build] In file included from C:/Data/repos/samples_vk/framework\hpp_fence_pool.h:20:
[build] C:/Data/repos/samples_vk/framework\fence_pool.h:48:25: error: cannot initialize a parameter of type 'uint64_t' (aka 'unsigned long long') with an lvalue of type 'unsigned long long () noexcept'
[build] 48 | VkResult wait(uint64_t timeout = std::numeric_limits<uint64_t>::max()) const;
[build] | ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[build] C:/Data/repos/samples_vk/framework\fence_pool.h:48:25: note: passing argument to parameter 'timeout' here
[build] In file included from C:/Data/repos/samples_vk/framework/core/debug.cpp:20:
[build] In file included from C:/Data/repos/samples_vk/framework\core/command_buffer.h:32:
[build] In file included from C:/Data/repos/samples_vk/framework\rendering/subpass.h:21:
[build] C:/Data/repos/samples_vk/framework\buffer_pool.h:349:65: error: expected unqualified-id
[build] 349 | vk::DeviceSize new_block_size = minimal ? minimum_size : std::max(block_size, minimum_size);
[build] | ^
[build] C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\shared\minwindef.h:193:29: note: expanded from macro 'max'
[build] 193 | #define max(a,b) (((a) > (b)) ? (a) : (b))
[build] | ^
[build] 5 errors generated.

@asuessenbach
Copy link
Copy Markdown
Contributor

I think the better approach to resolve the errors on min/max here would be to define

#ifndef NOMINMAX
#define NOMINMAX

before including Windows.h, which kind of "resolves" the issue at its root.

@Stellarist Stellarist force-pushed the fix_windows_macro_conflict branch from 1775a8e to 2438ab9 Compare March 4, 2026 10:47
@Stellarist
Copy link
Copy Markdown
Author

Stellarist commented Mar 4, 2026

I think the better approach to resolve the errors on min/max here would be to define

Thanks! I replaced the if(MSVC) check with if(WIN32) in CMake for all Windows builds.

@marty-johnson59 marty-johnson59 merged commit 0e8f199 into KhronosGroup:main Mar 9, 2026
19 checks passed
@Stellarist Stellarist deleted the fix_windows_macro_conflict branch March 21, 2026 05:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants