C++ use of bool

Tony van der Hoff OSLib at mk-net.demon.co.uk
Thu May 18 09:49:40 BST 2000


On Wed, 17 May 2000, at 16:42:22, David Bryan
<D.J.Bryan at cranfield.ac.uk> wrote on the subject "C++ use of bool":

>In message <VI+M6OAbEqI5Ew$5 at mk-net.demon.co.uk>
>          Tony van der Hoff <OSLib at mk-net.demon.co.uk> wrote:
>
>
>g++ defines both |__GNUG__| and |__GNUC__|, but only
>|__GNUC_MINOR__|; there is no |__GNUG_MINOR__|.
>
Ah, OK.
>
>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 )

Are you trying to confuse me (not hard :)?       ^

>      #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
>

OK, I see what you mean. Perhaps it would be cleaner to handle the
exceptions specifically; that would make it easier to add to them if and
when the need arises:

 
/* C++ (1998) defines bool as a keyword;
** many implementations included it earlier
*/
#if !defined( BOOL_DEFINED ) && defined( __cplusplus )
  /* assume its's fully C++ compliant */
  #define BOOL_DEFINED

  /* CFront defines |__cplusplus| but not |bool| */
  /* We assume that CFront is only ever used with Norcroft C */
  /* any C99 version of Norcroft will have been trapped earlier */
  #if defined __CC_NORCROFT
    #undef BOOL_DEFINED
  #endif

  /* GNU C++ defines bool as a keyword from V2.7 onwards */
  #if defined __GNUG__
    #if __GNUG__ < 2 || ( __GNUG__ == 2 && __GNUC_MINOR__ < 7 )
      #undef BOOL_DEFINED
    #endif
  #endif

  /* any other exceptions here */
#endif


How about that?
Tony

-- 
Tony van der Hoff         |  Mailto:tony at mk-net.demon.co.uk
                          |  Mailto:avanderhoff at iee.org
Buckinghamshire, England  |  http:www.mk-net.demon.co.uk



More information about the oslib-user mailing list