C++ use of bool
Daniel Ellis
dre at mssl.ucl.ac.uk
Wed May 17 15:57:49 BST 2000
Tony van der Hoff writes:
> On Fri, 5 May 2000, at 16:06:10, David Bryan <D.J.Bryan at cranfield.ac.uk>
> wrote on the subject "C++ use of bool":
>
> >In message <sKii6NAb9oE5EwYI at mk-net.demon.co.uk>
> > Tony van der Hoff <OSLib at mk-net.demon.co.uk> wrote:
> >
> >> On Thu, 4 May 2000, at 17:50:51, David Bryan <D.J.Bryan at cranfield.ac.uk>
> >> wrote on the subject "C++ use of bool":
> >>
> >
> >As it turns out, g++ hasn't always had |bool| as a keyword.
>
> My fledgling types.h now contains this:
>
> --------------------------------------------------------
>
> /* C99 defines bool as a keyword */
> #if !defined BOOL_DEFINED && defined ( __STDC_VERSION__ )
> #if __STDC_VERSION__ >= 199901L
> #define BOOL_DEFINED
> #endif
> #endif
>
> /* GNU C++ defines bool as a keyword at V2.7 */
> #if !defined BOOL_DEFINED && defined __GNUG__
> #if __GNUG__ > 2 || ( __GNUG__ == 2 && __GNUG_MINOR__ >= 7 )
> #define BOOL_DEFINED
> #endif
> #endif
>
> /* C++ (1998) defines bool as a keyword,
> ** but many implementations included it earlier
> */
> #if !defined( BOOL_DEFINED ) && defined __cplusplus
> /* CFront defines |__cplusplus| but not |bool| */
> if !defined __CC_NORCROFT
> #define BOOL_DEFINED
> #endif
> #endif
>
> #if !defined( BOOL_DEFINED )
> typedef osbool bool;
> #endif
>
> --------------------------------------------------------
>
> Does anyone want to comment/criticise? Are there any other little twists
> that I ought to know about before committing to this?
Shouldn't # be the first character on the line? I've usually seen
indented preprocessor statements as:
#if THIS
/* only do is THIS */
# if THAT
/* only do if THIS and THAT */
# endif
#endif
Also, you've missed out a # on 'if !defined __CC_NORCROFT'
cheers,
--
Dan Ellis
Software Engineer
Climate Physics Group
Mullard Space Science Laboratory
More information about the oslib-user
mailing list