Skip to content

Commit 5bec589

Browse files
authored
windows: guard static_assert with __STDC_VERSION__ for C99 compatibility (#810)
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
1 parent 78f95a3 commit 5bec589

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

windows/hidapi_descriptor_reconstruct.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,12 @@ typedef struct hid_pp_link_collection_node_ {
124124
// Although very unlikely, it might still be possible that the compiler creates a memory layout that is
125125
// not binary compatile.
126126
// Other structs are not checked at the time of writing.
127+
// static_assert was added to <assert.h> in C11; skip this check when the
128+
// translation unit is compiled as C99 or earlier, where it is unavailable.
129+
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
127130
static_assert(sizeof(struct hid_pp_link_collection_node_) == 16,
128131
"Size of struct hid_pp_link_collection_node_ not as expected. This might break binary compatibility");
132+
#endif
129133

130134
typedef struct hidp_unknown_token_ {
131135
UCHAR Token; /* Specifies the one-byte prefix of a global item. */

0 commit comments

Comments
 (0)