Topic: bool-- (was: From C++ to Shining C)


Author: Michael Cook <mcook@cognex.com>
Date: 1995/07/18
Raw View
>>>>> "H" == H  <mike@if.com> writes:

 H> What if b is already -1 (true)?  then...

b is of type `bool'.
It can be only `false' or `true'.
It can't be -1.

int(false) is 0.
int(true) is 1.

int(bool(-1)) is 1.
int(bool(42)) is 1.

Michael.





Author: mike@if.com (Mr.H)
Date: 1995/07/17
Raw View
On 14 Jul 1995 19:06:31 GMT, Michael Cook (mcook@cognex.com) wrote:
- >>>>> "SU" == Shankar Unni <shankar@sgi.com> writes:

-  SU> I guess the intent was that implementations can quietly implement bool as
-  SU> "unsigned char" and do nothing else, but that's clearly silly, since they
-  SU> would still have to guard against 256 ++'s in a row.

- No, it looks like the intent was that `++' and `--' could be impelemented for
- `bool' in the same way as for other integers:

-    ++b   is    b=b+1    is   b=1+1    is   b=bool(2)    is b=true
-                         or   b=0+1    is   b=bool(1)    is b=true

- and

-    --b   is    b=b-1    is   b=1-1    is   b=bool(0)    is b=false
-                         or   b=0-1    is   b=bool(-1)   is b=true

- In other words, `++b' does the Just Works, as they say.
- But `--b' doesn't.

- Michael.

What if b is already -1 (true)?  then...

   ++b   is    b=b+1    is   b=-1+1    is   b=bool(0)    is b=false

Clearly, if b is being treated as a signed integral type then the
'b++ is always true' statement has to be false, doesn't it?

--
-------------------------------------------------------------------
-- Mr.H - mike@mrhappy.if.com                                    --
-- All opinions expressed herein are my own... right?            --
-- "Things are more like they are now than they have ever been." --
--    - Gerald Ford                                              --
-------------------------------------------------------------------





Author: Michael Cook <mcook@cognex.com>
Date: 1995/07/14
Raw View
>>>>> "SU" == Shankar Unni <shankar@sgi.com> writes:

 SU> I guess the intent was that implementations can quietly implement bool as
 SU> "unsigned char" and do nothing else, but that's clearly silly, since they
 SU> would still have to guard against 256 ++'s in a row.

No, it looks like the intent was that `++' and `--' could be impelemented for
`bool' in the same way as for other integers:

   ++b   is    b=b+1    is   b=1+1    is   b=bool(2)    is b=true
                        or   b=0+1    is   b=bool(1)    is b=true

and

   --b   is    b=b-1    is   b=1-1    is   b=bool(0)    is b=false
                        or   b=0-1    is   b=bool(-1)   is b=true

In other words, `++b' does the Just Works, as they say.
But `--b' doesn't.

Michael.