Support C99
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
Research direction
Start with the CLI standards in src/nunavut/cli/__init__.py, C language configuration in src/nunavut/lang/properties.json, and support and base templates in src/nunavut/lang/c/support/serialization.j2 and src/nunavut/lang/c/templates/base.j2. Add C99 selection at generation time, then audit generated code and extend strict C and C++ verification for the listed cases. Done means the C99 matrix passes, incompatible modes retain clear diagnostics, and C11/C17/C23 output has no C99 fallback.
Written by the indexing model from the issue text.
Description
Issue from public_regulated_data_types.
Add C99 as a supported output standard for the C generator. The original report identifies two problems: nnvg -std=c99 is rejected, and the generated serialization support header requires C11 or newer. This requires implementation and verification, rather than guidance to upgrade to the 3.0 preview.
Findings
Checked main at 43fec8ad5646f978f3619b4623a32be7f0c1a6ec and 3.0.preview at b803f24b531be6f1ce9d8b53f4936cb4f977c45d:
- The CLI accepts
c11,c17, andc23, but notc99. - The C language configuration defaults to C11 and uses
_Static_assertfor C11/C17 andstatic_assertfor C23. - The support header explicitly rejects C compilation when
__STDC_VERSION__ < 201112L. - The current C verification targets cover C11/C17/C23, with no C99 target. The earlier comment in the linked issue that C99 compatibility was tested is not supported by the current matrix.
- Reproduced with a generated sample containing an integer, floating-point field, and variable-length array:
-std=c99fails argument parsing; C11 output failsclang -std=c99 -pedantic-errors -fsyntax-onlyon the version guard and_Static_assert; the same output passes under C11.
Relevant sources: CLI standards, C language configuration, support-header guard and assertions.
Select compatibility code at generation time
We are generating code. Select the C99 implementation in the generator/templates, based on the requested output standard.
- Do not emit runtime
if c99branches or compiler-version conditionals that choose between C99 and newer implementations in every generated header. - Emit C99 compatibility helpers/macros only when generating with C99 support. A C99-targeted header can use its generated assertion helper directly.
- C11/C17/C23 output must retain its native static assertions and must not acquire a C99 fallback that silently allows compilation in an incompatible language mode.
- Keep explicit compiler-language/version guards with clear diagnostics for unsupported compilation modes. These guards reject incompatible use; they do not select a compatibility implementation. Check the requirement for each selected output standard rather than assuming the shared C11 minimum is sufficient for every target.
- Preserve the configured C++ compatibility behavior and test it separately.
Some protection already exists: the support header has a clear C11 minimum-version #error, and generated type headers have native static assertions rejecting serialization support built with different language options (template). Preserve these protections. For an older compiler that cannot parse native static assertions, the explicit version #error is needed for the clear diagnostic; unsupported assertion syntax alone is not sufficient.
Robust C99 compile-time assertions
A named structure with a bit-field provides a portable C99 assertion at file or block scope:
#include <limits.h>
#include <stdint.h>
/* Emit this helper only for C99-targeted output. */
#define NUNAVUT_C99_ASSERT(condition, name) \
struct nunavut_assert_##name { \
unsigned int check : ((condition) ? 1 : -1); \
}
NUNAVUT_C99_ASSERT(sizeof(uint64_t) * CHAR_BIT == 64,
uint64_must_have_64_bits);
C99 requires a bit-field width to be an integer constant expression with a nonnegative value (C99 committee draft, section 6.7.2.1):
- A true condition produces a valid width of 1.
- A false condition produces an invalid width of -1.
- A nonconstant condition is also invalid, so the check cannot accidentally become a runtime check.
- This declares a type only: no object, storage, or runtime work is introduced.
Generate unique, descriptive names, including the type/version and assertion identity where needed to avoid collisions across generated headers. Alternatively, emit the structure declaration directly for each C99 assertion and avoid the helper macro altogether. Diagnostics are less expressive than native static-assert message strings, so preserve useful context in the generated names/comments.
The common typedef char name[(condition) ? 1 : -1] approach can become a variable-length array at block scope if its condition is not constant. The bit-field approach avoids that trap. Checked the bit-field mechanism at file and block scope with GCC and Clang using -std=c99 -pedantic-errors -Wall -Wextra -Werror: true conditions pass; false and nonconstant conditions fail. This validates the mechanism, not full C99 support for all generated code.
Work required to close
- Accept
-std=c99and add the corresponding C language configuration. - Generate the C99 version guard and compile-time assertion implementation at generation time; audit the remaining generated constructs for strict C99 compatibility.
- Keep native assertions and clear rejection diagnostics for incompatible use of other output standards, including mismatched type/support-header generation options.
- Add strict C99 compilation and serialization verification, including floats, arrays, unions, and delimited types.
- Test assertion success/failure/nonconstant cases, multiple assertions and generated headers in one translation unit, and the existing C++ compatibility mode.
- Verify C11/C17/C23 output contains no new C99 fallback helpers or implementation-selection branches.
- Update supported-standard documentation and CLI help. The current help mentions C99 even though the CLI rejects it.
- Dominant language
- Python
- Stars
- 48
- Forks
- 26
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 9
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from OpenCyphal/nunavut
-
build and test dependencies
Difficulty 4/5 3-5 days Newbie friendliness 55/100
OpenCyphal/nunavut#419 ·
Maintainers usually reply within 1 day
-
build and test C++ dependencies
Difficulty 4/5 3-5 days Newbie friendliness 50/100
OpenCyphal/nunavut#418 ·
Maintainers usually reply within 1 day
-
build and test Python
Difficulty 4/5 3-5 days Newbie friendliness 45/100
OpenCyphal/nunavut#416 ·
Maintainers usually reply within 1 day
-
C C++ Python
Difficulty 4/5 3-5 days Newbie friendliness 52/100
OpenCyphal/nunavut#414 · 1 comment ·
Maintainers usually reply within 1 day
-
feature under consideration
Difficulty 5/5 Over a week Newbie friendliness 32/100
OpenCyphal/nunavut#413 ·
Maintainers usually reply within 1 day
All issues in OpenCyphal/nunavut
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 86/100
py-econometrics/pyfixest#2072 ·
Maintainers usually reply within 1 day
-
~planning docs
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
Kromatic-Innovation/athenaeum#3084 ·
Maintainers usually reply within 1 day
-
Bosch Room Thermostat II number entities offer -500 to 3000 °C setpoint limits and a -32768 to 32767 °C outdoor temperaturePossibly taken @zigpy-review-bot claimed this today. Openbot: code audit
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
zigpy/zha-device-handlers#5769 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 Half a day Newbie friendliness 80/100
R0Y00/Xbox2Windows#254 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Kludex/python-multipart#375 ·
Maintainers usually reply within 1 day