Skip to content

MSVC Compatibility Macros#35

Open
vijayee wants to merge 2 commits into
DavidLeeds:masterfrom
vijayee:master
Open

MSVC Compatibility Macros#35
vijayee wants to merge 2 commits into
DavidLeeds:masterfrom
vijayee:master

Conversation

@vijayee

@vijayee vijayee commented Jun 19, 2026

Copy link
Copy Markdown

This adds portability and usability to the MSVC compiler

vijayee added 2 commits June 19, 2026 09:31
Upstream commit 5a4ba02 dropped the generator expression that restricted -Wall -Werror to GCC. MSVC's cl.exe rejects -Werror as an invalid numeric argument (D8021), so any project that pulls hashmap in via add_subdirectory on Windows fails to configure. Restore the generator expression and extend it to Clang and AppleClang, matching the intent of the original line.
MSVC's C compiler rejects several constructs that hashmap.h relies on:

  - typeof() is a GCC extension
  - statement expressions ({ ... }) are GCC-only
  - C99 compound literals (Type){ ... } are not in MSVC's C
  - zero-size struct arrays are illegal

The hashmap header template uses each of these for type-safe iteration
and the HASHMAP() macro. Provide MSVC-compatible variants behind
__HASHMAP_MSVC, gated on _MSC_VER. The public API (macro names, struct
field layout) is unchanged.

src/hashmap.c: hashmap_calc_table_size() calls __builtin_clzl, which
does not exist on MSVC. Provide a local _BitScanReverse-backed shim
under the same _MSC_VER guard.

Together these let liboffs (and any other project that consumes the
vijayee/hashmap fork) build cleanly with MSVC.
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.

1 participant