Re: "a < b < c" not the same as "(a < b) && (b < c)"?
- From: Tim Rentsch <txr@xxxxxxxxxxxxxxxxxxx>
- Date: 18 Oct 2005 09:31:46 -0700
Keith Thompson <kst-u@xxxxxxx> writes:
> Tim Rentsch <txr@xxxxxxxxxxxxxxxxxxx> writes:
> > August Karlstrom <fusionfive@xxxxxxxxx> writes:
> >> Keith Thompson wrote:
> >> > August Karlstrom <fusionfive@xxxxxxxxx> writes:
> >> >>OK, let me rephrase that: C has no native (primitive) boolean type.
> >> >
> >> > Yes, it does. It's called _Bool (or bool with "#include <stdbool.h>").
> >>
> >> OK, you're right, sorry. The existence of the header file has made me
> >> think it's not a native type. So _Bool is just an integer type that can
> >> hold two values: 0 or 1, and it's called _Bool just to minimize the risk
> >> of breaking existing programs, right?
> >
> > The type _Bool is an integer type that can hold only two
> > values, those being 0 and 1. However, it's different
> > from other integer types in some important ways:
> >
> > 1. Assigning a zero value to a _Bool results in 0, and
> > assigning any non-zero value to a _Bool results in 1.
> > (Same for conversion.) No other integer type behaves
> > this way (in all implementations).
>
> It's all about conversion. The only way to assign a non-zero value to
> a _Bool is to convert it to _Bool (unless it's already of type _Bool).
> The conversion rules say that the result is always 0 or 1.
Yes, but it's not only that the result is always 0 or 1.
An unsigned int bitfield of length one always holds either
0 or 1. But only _Bool maps any non-zero value to 1 and
only zero values to 0. There are conversions going on
in both cases (of bitfield and _Bool), but the conversion
rules for _Bool are different from those of any other
integer type.
.
- Follow-Ups:
- Re: "a < b < c" not the same as "(a < b) && (b < c)"?
- From: Keith Thompson
- Re: "a < b < c" not the same as "(a < b) && (b < c)"?
- References:
- "a < b < c" not the same as "(a < b) && (b < c)"?
- From: Paminu
- Re: "a < b < c" not the same as "(a < b) && (b < c)"?
- From: August Karlstrom
- Re: "a < b < c" not the same as "(a < b) && (b < c)"?
- From: Keith Thompson
- Re: "a < b < c" not the same as "(a < b) && (b < c)"?
- From: August Karlstrom
- Re: "a < b < c" not the same as "(a < b) && (b < c)"?
- From: Keith Thompson
- Re: "a < b < c" not the same as "(a < b) && (b < c)"?
- From: August Karlstrom
- Re: "a < b < c" not the same as "(a < b) && (b < c)"?
- From: Tim Rentsch
- Re: "a < b < c" not the same as "(a < b) && (b < c)"?
- From: Keith Thompson
- "a < b < c" not the same as "(a < b) && (b < c)"?
- Prev by Date: Re: null function pointer?
- Next by Date: Re: malloc
- Previous by thread: Re: "a < b < c" not the same as "(a < b) && (b < c)"?
- Next by thread: Re: "a < b < c" not the same as "(a < b) && (b < c)"?
- Index(es):
Relevant Pages
|
Loading