From cac4e146da1a6324cc0e56795f966baf159b0bc7 Mon Sep 17 00:00:00 2001 From: Ihor Dutchak Date: Wed, 20 May 2026 23:42:42 +0300 Subject: [PATCH] windows: guard static_assert with __STDC_VERSION__ for C99 compatibility windows/hidapi_descriptor_reconstruct.h uses static_assert() to sanity-check the layout of hid_pp_link_collection_node_. static_assert was added to 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 --- windows/hidapi_descriptor_reconstruct.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/windows/hidapi_descriptor_reconstruct.h b/windows/hidapi_descriptor_reconstruct.h index 6471204b2..42f9fb4f3 100644 --- a/windows/hidapi_descriptor_reconstruct.h +++ b/windows/hidapi_descriptor_reconstruct.h @@ -124,8 +124,12 @@ typedef struct hid_pp_link_collection_node_ { // Although very unlikely, it might still be possible that the compiler creates a memory layout that is // not binary compatile. // Other structs are not checked at the time of writing. +// static_assert was added to in C11; skip this check when the +// translation unit is compiled as C99 or earlier, where it is unavailable. +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L static_assert(sizeof(struct hid_pp_link_collection_node_) == 16, "Size of struct hid_pp_link_collection_node_ not as expected. This might break binary compatibility"); +#endif typedef struct hidp_unknown_token_ { UCHAR Token; /* Specifies the one-byte prefix of a global item. */