Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

_Bool data type of C99

Tags:

c

boolean

c99

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?

like image 261
HelloWorld Avatar asked Nov 30 '22 11:11

HelloWorld


2 Answers

_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.

like image 77
Vlad from Moscow Avatar answered Dec 04 '22 02:12

Vlad from Moscow


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.

like image 28
pablo1977 Avatar answered Dec 04 '22 01:12

pablo1977