问题
The C99 standard of the C programming language defines the _Bool data type as a macro for another data type (as the language isn't able to deal with a type safe boolean).
Is the _Bool a macro for unsigned char, unsigned int or some other data type?
回答1:
_Bool is a separate integere type that according to the C Standard. _Bool is a keyword of the C language.
2 An object declared as type _Bool is large enough to store the values 0 and 1.
_Bool is unsigned integer type.
The type _Bool and the unsigned integer types that correspond to the standard signed integer types are the standard unsigned integer types.
And there should be mentioned that
— The rank of _Bool shall be less than the rank of all other standard integer types.
回答2:
The _Bool type is a new type appearing in the standard C99.
It is an unsigned integer type.
Its range of values it has to be able to hold the values 0 and 1.
The range of values of _Bool is contained in the range of values of any other unsigned integer type.
The keyword _Bool is used instead of bool because the standard rationale suppose that there exists in the existing practice (before 1999) several and different uses of the identifier bool (as a macro or well as a typedef).
The standard header <stdbool.h> defines the macro bool as meaning exactly _Bool.
Also, the (macro) constants true and false are defined as being 1 and 0 respectively.
Although the intent is to use the word bool, the programer can choose to use or not the standard type _Bool or well to give his own definition of bool.
回答3:
C99 defines a new type _Bool.
It also defines a new header file stdbool.h that includes the line:
#define bool _Bool
来源:https://stackoverflow.com/questions/24602814/bool-data-type-of-c99