Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
Old C90 compilers do not provide stdbool.h, nor do they provide stdint.h. If you have one of them but not the other, then your compiler is dysfunctional somehow. Here's from an old production code...
#2: Post edited
- Old C90 compilers do not provide `stdbool.h`, nor do they provide `stdint.h`. If you have one of them but not the other, then your compiler is dysfunctional somehow.
- Here's from an old production code header of mine that is used with old crappy compilers for 8/16 bit targets:
- (it happens to add `BOOL TRUE FALSE` also as they were common in C90, but you probably don't need those)
- ```c
- #ifdef __STDC_VERSION__
- #if (__STDC_VERSION__ >= 199901L) /* C99 or later? */
- #include <stdint.h>
- #include <stdbool.h>
- typedef bool BOOL;
- #ifndef FALSE
- #define FALSE false
- #define TRUE true
- #endif
- #else
- #define C90_COMPILER
- #endif /* #if (__STDC_VERSION__ >= 199901L) */
- #else
- #define C90_COMPILER
- #endif /* __STDC_VERSION__ */
- #ifdef C90_COMPILER
- typedef unsigned char uint8_t;
- typedef unsigned int uint16_t;
- typedef unsigned long uint32_t;
- typedef signed char int8_t;
- typedef signed int int16_t;
- typedef signed long int32_t;
- #ifndef BOOL
- #ifndef FALSE
- #define FALSE 0u
- #define false 0u
- #define TRUE 1u
- #define true 1u
- #endif
- typedef uint8_t BOOL;
- typedef uint8_t bool;
- #endif
- #endif /* C90_COMPILER */
- ```
- The explanation is that the constant `__STDC_VERSION__` was added in ISO C 9899:1990 + Amd1 1995, aka "C95". Neither the original C90 or C95 had support for the required headers however - in case either of those standards are used, this code defines a placeholder token `C90_COMPILER`.
Then in case of C90, define all common types from `stdint.h` and `stdbool.h`. You'd define `bool` as `uint8_t` indeed. You _could_ just ignore all of this and use `uint8_t` with value 1 or 0 too, but that's less self-explanatory and means that you are still in the situation where you can't use semi-modern libs that come with the type `bool`.
- Old C90 compilers do not provide `stdbool.h`, nor do they provide `stdint.h`. If you have one of them but not the other, then your compiler is dysfunctional somehow.
- Here's from an old production code header of mine that is used with old crappy compilers for 8/16 bit targets:
- (it happens to add `BOOL TRUE FALSE` also as they were common in C90, but you probably don't need those)
- ```c
- #ifdef __STDC_VERSION__
- #if (__STDC_VERSION__ >= 199901L) /* C99 or later? */
- #include <stdint.h>
- #include <stdbool.h>
- typedef bool BOOL;
- #ifndef FALSE
- #define FALSE false
- #define TRUE true
- #endif
- #else
- #define C90_COMPILER
- #endif /* #if (__STDC_VERSION__ >= 199901L) */
- #else
- #define C90_COMPILER
- #endif /* __STDC_VERSION__ */
- #ifdef C90_COMPILER
- typedef unsigned char uint8_t;
- typedef unsigned int uint16_t;
- typedef unsigned long uint32_t;
- typedef signed char int8_t;
- typedef signed int int16_t;
- typedef signed long int32_t;
- #ifndef BOOL
- #ifndef FALSE
- #define FALSE 0u
- #define false 0u
- #define TRUE 1u
- #define true 1u
- #endif
- typedef uint8_t BOOL;
- typedef uint8_t bool;
- #endif
- #endif /* C90_COMPILER */
- ```
- The explanation is that the constant `__STDC_VERSION__` was added in ISO C 9899:1990 + Amd1 1995, aka "C95". Neither the original C90 or C95 had support for the required headers however - in case either of those standards are used, this code defines a placeholder token `C90_COMPILER`.
- Then in case of C90, define all common types from `stdint.h` and `stdbool.h`. You'd define `bool` as `uint8_t` indeed. You _could_ just ignore all of this and use `uint8_t` with value 1 or 0 too, but that's less self-explanatory and means that you are still in the situation where you can't use semi-modern libs that come with the type `bool`.
- Also for MISRA C compliance you typically need to tell the MISRA checker what your Boolean type is called and this was the case even with old MISRA C:2004. All MISRA versions strongly encourage using `stdint.h` types or equivalents.
#1: Initial revision
Old C90 compilers do not provide `stdbool.h`, nor do they provide `stdint.h`. If you have one of them but not the other, then your compiler is dysfunctional somehow.
Here's from an old production code header of mine that is used with old crappy compilers for 8/16 bit targets:
(it happens to add `BOOL TRUE FALSE` also as they were common in C90, but you probably don't need those)
```c
#ifdef __STDC_VERSION__
#if (__STDC_VERSION__ >= 199901L) /* C99 or later? */
#include <stdint.h>
#include <stdbool.h>
typedef bool BOOL;
#ifndef FALSE
#define FALSE false
#define TRUE true
#endif
#else
#define C90_COMPILER
#endif /* #if (__STDC_VERSION__ >= 199901L) */
#else
#define C90_COMPILER
#endif /* __STDC_VERSION__ */
#ifdef C90_COMPILER
typedef unsigned char uint8_t;
typedef unsigned int uint16_t;
typedef unsigned long uint32_t;
typedef signed char int8_t;
typedef signed int int16_t;
typedef signed long int32_t;
#ifndef BOOL
#ifndef FALSE
#define FALSE 0u
#define false 0u
#define TRUE 1u
#define true 1u
#endif
typedef uint8_t BOOL;
typedef uint8_t bool;
#endif
#endif /* C90_COMPILER */
```
The explanation is that the constant `__STDC_VERSION__` was added in ISO C 9899:1990 + Amd1 1995, aka "C95". Neither the original C90 or C95 had support for the required headers however - in case either of those standards are used, this code defines a placeholder token `C90_COMPILER`.
Then in case of C90, define all common types from `stdint.h` and `stdbool.h`. You'd define `bool` as `uint8_t` indeed. You _could_ just ignore all of this and use `uint8_t` with value 1 or 0 too, but that's less self-explanatory and means that you are still in the situation where you can't use semi-modern libs that come with the type `bool`.
