Is it possible to define your own Boolean types?

Moderators: misra-c, david ward

Post Reply
andrea96b1
Posts: 1
Joined: Tue Apr 14, 2020 10:38 am
Company: federico ii di napoli

Is it possible to define your own Boolean types?

Post by andrea96b1 » Mon Jul 06, 2020 8:44 am

Hello,

I want to know if it is possible to define a Boolean type and do not use the one defined in the stdbool.h. Can I define Boolean like this:

Code: Select all

typedef uint8_t boolean;
and

Code: Select all

#define TRUE 0x1
and

Code: Select all

#define FALSE 0x0
? And If I define Boolean in this way, what operations, which if done using standard booleans would I violate?

Sorry in advance If the question is not too clear and If I made some mistake.

misra-c
Posts: 572
Joined: Thu Jan 05, 2006 1:11 pm

Re: Is it possible to define your own Boolean types?

Post by misra-c » Wed Aug 05, 2020 9:29 am

The MISRA-C working group recommends the use of the stdbool.h version of bool where available.
However Appendix D.6 on Boolean constants says:
" Tools may also provide additional ways of identifying essential Boolean types."
It is therefore possible to define a boolean type as you have done. The MISRA C:2012 rules on essentially boolean types will then apply.
---
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “8.10 The essential type model”