Skip to content

Improve C89/C90 compatibility by conditionally including <stdint.h> #7

Description

@TLevitner

The current implementation unconditionally includes the standard header file <stdint.h>. While this is valid for C99 and later standards, some toolchains, such as IAR Embedded Workbench configured for C89/C90 compliance, may not provide this header, resulting in compilation errors.

To improve compatibility with older C language standards while preserving existing functionality, the inclusion of <stdint.h> should be conditioned on the detected language standard.

Current Code

#include <stdint.h>

Proposed Fix

#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L)
  /* C89/C90 mode: Define standard integer types locally */
#else
  /* C99 and later: Use standard stdint.h */
  #include <stdint.h>
#endif

Rationale

<stdint.h> is part of the C99 standard and is not guaranteed to be available when compiling in C89/C90 mode. The proposed change allows the code to compile in both C89/C90 and C99+ environments by only including <stdint.h> when the language standard supports it.

Expected Benefit

  • Improved compatibility with C89/C90 toolchains, including IAR Embedded Workbench.
  • No functional impact on existing C99 and newer builds.
  • Better portability across different compiler configurations.

Metadata

Metadata

Assignees

Labels

cmsisCMSIS-related issue or pull-requestenhancementNew feature or request

Projects

Status
Analyzed

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions