Why did "bool” cause compilation errors

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Why did "bool” cause compilation errors

1,126 Views
whagiew
Contributor II

hi,

I use "bool" in the s32ds.exe project, but the compiler reports an error. How do I use bool in my project?
Thanks.
Best regards
yang

5 Replies

946 Views
BlackNight
NXP Employee
NXP Employee

Hi yang,

'bool' is not a keyword in the C programming language. To use it, make sure you include stdbool.h:

#include <stdbool.h>

in your sources.

I hope this helps,

Erich

946 Views
whagiew
Contributor II

thanks, the problem is solved with your help.

0 Kudos

946 Views
bobpaddock
Senior Contributor III

An unanswerable question is why is it 'bool' and not 'bool_t' to match <stdint.h> types? 

Inconsistencies like this are annoying.

0 Kudos

946 Views
danielchen
NXP TechSupport
NXP TechSupport

stdbool.h defines bool as a macro because the C standard 7.18

stdint.h defines intN_t as typedefs because the C standard 7.20

You can use one or the other to achieve the same effect, but it's better to use the proper one to your needs, you need to consider the compatibility of the your project.

Regards

Daniel.

0 Kudos

946 Views
bobpaddock
Senior Contributor III

The point is 'bool' is used as a type, it should end with a _t.

The heading of 7.16 clearly states 'bool' is a type:


"7.16 Boolean type and values".

By convention macros in C are upper case then by 7.18 it should 

be BOOL, or properly BOOL_T.


We may be looking at different version of the standard as the one I'm looking at has 7.20 as:

7.20 General utilities <stdlib.h>

0 Kudos