windows: guard static_assert with __STDC_VERSION__ for C99 compatibility#810
Merged
Conversation
windows/hidapi_descriptor_reconstruct.h uses static_assert() to sanity-check the layout of hid_pp_link_collection_node_. static_assert was added to <assert.h> in C11; building with -std=c99 (e.g. set(CMAKE_C_STANDARD 99) in a parent project) on mingw/gcc fails at that line because the identifier is undeclared. The assertion's preceding comment describes it as a "risk-reduction measure" rather than a strict requirement, so guard it with `#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L`. C11/C17/C23 toolchains still get the compile-time check; older standards (and MSVC default C mode, where __STDC_VERSION__ is not typically set that high) skip it and build cleanly. Closes: #764 Assisted-by: Claude:claude-opus-4.7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
windows/hidapi_descriptor_reconstruct.h:127usesstatic_assertto sanity-check the in-memory layout ofhid_pp_link_collection_node_:static_assertwas added to<assert.h>in C11. Building with-std=c99— for example viaset(CMAKE_C_STANDARD 99)in a parent CMake project, as reported in #764 — fails at that line on mingw/gcc:Change
The assertion's preceding comment describes it as a "risk-reduction-measure" rather than a strict requirement. Guard it:
__STDC_VERSION__is typically not set that high) also skips it — a minor reduction in the safety net there, but the production build is unaffected.Net diff: +4 / -0 in one file.
Verification
Reproduced and fixed locally with
x86_64-w64-mingw32-gcc(GCC 10, MinGW-w64) in WSL, compiling the real backend sources:-std=c99-std=c11error: expected declaration specifiers or '...' before 'sizeof'at L127Tested with both
windows/hid.candwindows/hidapi_descriptor_reconstruct.c(the two sources that include the affected header).Closes #764.
Drafted with Claude Code.