Why did "bool” cause compilation errors

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Why did "bool” cause compilation errors

1,155件の閲覧回数
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 返答(返信)

975件の閲覧回数
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

975件の閲覧回数
whagiew
Contributor II

thanks, the problem is solved with your help.

0 件の賞賛

975件の閲覧回数
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 件の賞賛

975件の閲覧回数
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 件の賞賛

975件の閲覧回数
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 件の賞賛