docs: make SW_STATIC_ASSERT always-active and portable to C89/C++98
Round-3 review: Codex requested changes; Claude/Kimi/Copilot raised the same
underlying issue. The pre-C11 SW_STATIC_ASSERT fallback expanded to nothing, so:
- it left a bare `;` at file scope, failing the header's own -std=c99 -Wpedantic
bar (`ISO C does not allow extra ';' outside of a function`);
- the enum-width ABI invariant was silently *unenforced* before C11 (a
-fshort-enums C99 build compiled clean);
- the `#if defined(__cplusplus)` branch wasn't version-gated, so it emitted
C++11 `static_assert` in C++98 mode and hard-errored there.
Replace the no-op with an always-active, semicolon-consuming assertion:
- C11 / C++11+ (incl. MSVC via _MSVC_LANG, since MSVC reports __cplusplus as
199711L without /Zc:__cplusplus) use native static_assert / _Static_assert,
which surface the message;
- older modes fall back to a negative-size-array `typedef`, which is a hard
compile error on failure and, being a declaration, consumes the trailing `;`
cleanly (no -Wpedantic / -Wextra-semi noise).
Also fix the load-time ABI-check example in C_CODING_STANDARDS.md §4: the message
hardcoded "expected major 1" while the condition uses EXPECTED_MAJOR (and the
draft header is major 0) -> now interpolates {EXPECTED_MAJOR}.
Verified across the reviewers' matrix, all with
-Wall -Wextra -Werror -Wconversion -Wshadow -Wpedantic -fsyntax-only:
- gcc/clang c99, c11, c17 -> clean;
- g++/clang++ c++11, c++17 -> clean; g++ c++98 -> clean (fallback path);
- gcc -fshort-enums now fails the width assertions in BOTH c99 and c17 (invariant
enforced even pre-C11);
- uv run pytest -> 42 passed.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> C
Claude Coder committed
c0e391a5a1d32211ca39539f7b75d194026d49d3
Parent: 5d19e3d