[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Groff] on type bool
From: |
Bernd Warken |
Subject: |
Re: [Groff] on type bool |
Date: |
Tue, 21 May 2002 10:13:36 +0200 |
User-agent: |
Mutt/1.2.5i |
On Mon, May 20, 2002 at 11:37:51PM +0200, Bernd Warken wrote:
> c) Implement `bool' as follows:
>
> #ifdef HAS_BOOL
> # define to_bool(x) bool((x))
> #else // not HAS_BOOL
> # define bool int
> # define false 0
> # define true 1
> # define to_bool(x) (x == 0) ? 0 : 1
> #endif // not HAS_BOOL
>
A much better implementation is
#ifndef HAS_BOOL
typedef int bool;
#define bool(x) ((x) == 0) ? 0 : 1
#define false 0
#define true 1
#endif // not HAS_BOOL
Then casting can be done by the C++ functional cast `bool(x)', while
the C style cast `(bool) x' will not work. Then `to_bool()' is not
not needed.
> Together with the requirement that all casting to `bool' must be
> performed via `to_bool()', this fulfills the ANSI C++ `bool' rules
> (1)-(4) above.
>
> d) In order to be able to transparently use `bool', the above
> implementation must be kept in a header file that is included anyway
> in any .cc source file. `groff-source/src/include/lib.h' seems to be
> a good choice. Or should it go to a file of its own.
>
> Comments welcome.
>
> Bernd Warken
>
> _______________________________________________
> Groff maillist - address@hidden
> http://ffii.org/mailman/listinfo/groff