C++ use of bool

David Bryan D.J.Bryan at cranfield.ac.uk
Wed May 17 16:42:22 BST 2000


In message <VI+M6OAbEqI5Ew$5 at mk-net.demon.co.uk>
          Tony van der Hoff <OSLib at mk-net.demon.co.uk> wrote:

> /* 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

g++ defines both |__GNUG__| and |__GNUC__|, but only
|__GNUC_MINOR__|; there is no |__GNUG_MINOR__|.

> /* 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

For g++ 2.4.5, |__cplusplus| is defined, and |__CC_NORCROFT| is
not define.  The following would probably be better.

  /* 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
  
  /* C++ (1998) defines bool as a keyword, 
  ** but many implementations included it earlier 
  */
  #elif !defined( BOOL_DEFINED ) && defined __cplusplus 
    /* CFront defines |__cplusplus| but not |bool| */
    #if !defined __CC_NORCROFT
      #define BOOL_DEFINED
    #endif
  #endif

Other than the above, and the missing # pointed out by Dan, it all
looks fine ;-)

-- 
David Bryan




More information about the oslib-user mailing list