Skip to content

fix: Resolve macro redefinition warnings#2525

Open
Skyaero42 wants to merge 6 commits intoTheSuperHackers:mainfrom
Skyaero42:fix/macro-redefined-warning
Open

fix: Resolve macro redefinition warnings#2525
Skyaero42 wants to merge 6 commits intoTheSuperHackers:mainfrom
Skyaero42:fix/macro-redefined-warning

Conversation

@Skyaero42
Copy link
Copy Markdown

@Skyaero42 Skyaero42 commented Apr 2, 2026

NUM_ALPHA_TILES in Generals\Wheightmapedit.h was unused and is removed
_WIN32_WINNT was unused and is removed
WIN32_LEAN_AND_MEAN was redefined in registry.cpp. Included win.h instead, which already handles this macro correctly.

…rnings.

Added guards for WIN32_LEAN_AND_MEAN, _WIN32_WINNT, and
NUM_ALPHA_TILES to prevent redefinition.

- Related to TheSuperHackers#499
- Related to TheSuperHackers#503
@Skyaero42 Skyaero42 added this to the Code foundation build up milestone Apr 2, 2026
@Skyaero42 Skyaero42 self-assigned this Apr 2, 2026
@Skyaero42 Skyaero42 added the Stability Concerns stability of the runtime label Apr 2, 2026
@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Apr 2, 2026

Greptile Summary

This PR removes three macro redefinition warnings by cleaning up stale or conflicting #define directives. In registry.cpp, the locally-defined WIN32_LEAN_AND_MEAN is replaced with an include of win.h (which guards the macro with #ifndef before defining it), since core_wwcommon already injects WIN32_LEAN_AND_MEAN as a compile definition project-wide. In thread.cpp, the ancient _WIN32_WINNT 0x0400 (Windows NT 4.0) define is dropped — it wasn't needed by any API call in the file and is not defined anywhere else in the project. In WHeightMapEdit.h, NUM_ALPHA_TILES 8 is removed because the included WorldHeightMap.h already defines it as 12, and no WorldBuilder source file uses the macro at all.

Confidence Score: 5/5

This PR is safe to merge; all changes are correct removals of redundant or conflicting preprocessor definitions.

All three changes are verified: WIN32_LEAN_AND_MEAN is already defined by core_wwcommon, _WIN32_WINNT 0x0400 is unused and the removed APIs remain available on any Windows target, and NUM_ALPHA_TILES is unused by WorldBuilder source files. No functional behavior changes.

No files require special attention.

Important Files Changed

Filename Overview
Core/Libraries/Source/WWVegas/WWDownload/registry.cpp Removes redundant WIN32_LEAN_AND_MEAN define and replaces direct <windows.h> include with win.h, which guards the macro properly via #ifndef
Core/Libraries/Source/WWVegas/WWLib/thread.cpp Removes stale _WIN32_WINNT 0x0400 define targeting Windows NT 4.0; the value is unused and redundant with modern SDK defaults
Generals/Code/Tools/WorldBuilder/include/WHeightMapEdit.h Removes NUM_ALPHA_TILES 8 macro that conflicted with WorldHeightMap.h's definition of 12; the macro has zero uses in WorldBuilder source files

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[registry.cpp] -->|#include| B[Registry.h]
    A -->|#include| C[win.h]
    C --> D{#ifndef WIN32_LEAN_AND_MEAN}
    D -->|not defined| E[#define WIN32_LEAN_AND_MEAN]
    D -->|already defined| F[skip define]
    E --> G[#include windows.h]
    F --> G
    H[core_wwcommon CMake] -->|compile definition| I[WIN32_LEAN_AND_MEAN pre-defined]
    I -.->|causes F path| D
    style A fill:#d4edda
    style C fill:#d4edda
    style H fill:#cce5ff
Loading

Reviews (6): Last reviewed commit: "fix: use correct header encapsulation" | Re-trigger Greptile

@bobtista
Copy link
Copy Markdown

bobtista commented Apr 2, 2026

Could we use add_compile_definitions(WIN32_LEAN_AND_MEAN) in cmake and clean up all the individual defines?

@xezon xezon added CompileBug Bug at compile time Fix Is fixing something, but is not user facing and removed Stability Concerns stability of the runtime labels Apr 3, 2026
@xezon
Copy link
Copy Markdown

xezon commented Apr 3, 2026

The Pull title needs some polishing.

@Skyaero42 Skyaero42 changed the title fix: Add preprocessor guards around macros to resolve redefinition warnings. fix: Resolve redefinition warnings of macro's Apr 4, 2026
@Skyaero42
Copy link
Copy Markdown
Author

The Pull title needs some polishing.

done

@Skyaero42 Skyaero42 requested a review from xezon April 4, 2026 16:28
Also sorting includes by alphabetic order
@xezon xezon changed the title fix: Resolve redefinition warnings of macro's fix: Resolve macro redefinition warnings Apr 5, 2026
#define WIN32_LEAN_AND_MEAN
#include <windows.h>

#include <win.h>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"win.h"

Sort alphabetically.

Copy link
Copy Markdown
Author

@Skyaero42 Skyaero42 Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was wondering already whether that would be in scope or not. Its done now

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It still uses <> instead of "", which is unusual.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CompileBug Bug at compile time Fix Is fixing something, but is not user facing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants