Skip to content

Commit ab01f75

Browse files
authored
Add stdint.readme for C90 compliance (#13)
Add a stdint.readme file to support toolchains that do not provide the stdint.h file for integer typedefs. With the provision of this file, the library can be used against C90 compilers. This PR also adds a CI check to ensure successful library builds when using the stdint.readme file for the standard C library header.
1 parent 8d9adfd commit ab01f75

File tree

4 files changed

+56
-2
lines changed

4 files changed

+56
-2
lines changed

.github/workflows/ci.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,17 @@ jobs:
145145
run: |
146146
git-secrets --register-aws
147147
git-secrets --scan
148+
custom-standard-c-header:
149+
runs-on: ubuntu-latest
150+
steps:
151+
- name: Clone This Repo
152+
uses: actions/checkout@v2
153+
- name: Build
154+
run: |
155+
mkdir -p override-include
156+
cp source/include/stdint.readme override-include/stdint.h
157+
cmake -S test -B build/ \
158+
-G "Unix Makefiles" \
159+
-DBUILD_CLONE_SUBMODULES=ON \
160+
-DCMAKE_C_FLAGS='-Wall -Wextra -Werror -I../override-include'
161+
make -C build/ coverity_analysis

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,10 @@ int main()
9797

9898
## Building the library
9999

100-
A compiler that supports **C89 or later** such as *gcc* is required to build the library.
100+
A compiler that supports **C90 or later** such as *gcc* is required to build the library.
101+
102+
Additionally, the library uses a header file introduced in ISO C99, `stdint.h`. For compilers that do not provide this header file, the [source/include](source/include) directory contains [stdint.readme](source/include/stdint.readme), which can be renamed to `stdint.h` to
103+
build the backoffAlgorithm library.
101104

102105
For instance, if the example above is copied to a file named `example.c`, *gcc* can be used like so:
103106
```bash

source/backoff_algorithm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
*/
2828

2929
/* Standard includes. */
30-
#include <stdlib.h>
3130
#include <assert.h>
31+
#include <stddef.h>
3232

3333
/* Include API header. */
3434
#include "backoff_algorithm.h"

source/include/stdint.readme

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#ifndef _STDINT_H
2+
#define _STDINT_H
3+
4+
/*******************************************************************************
5+
* THIS IS NOT A FULL stdint.h IMPLEMENTATION - It only contains the definitions
6+
* necessary to build the library code. It is provided to allow the library to
7+
* be built using compilers that do not provide their own stdint.h definition.
8+
*
9+
* To use this file:
10+
*
11+
* 1) Copy this file into a directory that is in your compiler's include path.
12+
* The directory must be part of the include path for system header file,
13+
* for example passed using gcc's "-I" or "-isystem" options.
14+
*
15+
* 2) Rename the copied file stdint.h.
16+
*
17+
*/
18+
19+
typedef signed char int8_t;
20+
typedef unsigned char uint8_t;
21+
typedef short int16_t;
22+
typedef unsigned short uint16_t;
23+
typedef long int32_t;
24+
typedef unsigned long uint32_t;
25+
typedef long long int64_t;
26+
typedef unsigned long long uint64_t;
27+
28+
#define INT8_MAX ( ( signed char ) 127 )
29+
#define UINT8_MAX ( ( unsigned char ) 255 )
30+
#define INT16_MAX ( ( short ) 32767 )
31+
#define UINT16_MAX ( ( unsigned short ) 65535 )
32+
#define INT32_MAX 2147483647L
33+
#define UINT32_MAX 4294967295UL
34+
#define INT64_MAX 9223372036854775807LL
35+
#define UINT64_MAX 18446744073709551615ULL
36+
37+
#endif /* _STDINT_H */

0 commit comments

Comments
 (0)