Beginner with OSLib

Tony van der Hoff OSLib at mk-net.demon.co.uk
Mon Sep 18 15:29:47 BST 2000


On Mon, 18 Sep 2000, at 13:55:51, Chris Rutter
<chris at willow.armlinux.org> wrote on the subject "Beginner with OSLib":

>On Mon, 18 Sep 2000, Tony van der Hoff wrote:
>
>> I fixed this for OSLib 6.10 in June '00. OSLib now defines its own
>> OSBOOL type, which for backward compatibility can be defined to bool.
>
>Oh ick yick yuck -- pardon my whinge, but I think, typographically, that
>`OSBOOL' is really ugly and it would be a shame to have to put it anywhere.
>
>I think the correct solution, /given/ that OSLib has always widely eaten
>up the `bool' bit of the namespace /anyway/ is to typedef if it it's
>not present, but leave it otherwise.  I think you can even do this by
>checking whether `BOOL_T' (or something) is defined, but if not, you
>can check `__STDC_VERSION__'.  Or perhaps just use `bool_t', or maybe
>`os_bool' (though that does somewhat seem to conflict naming practices);
>but that capital monster is horrid. ;-)
>

Well, you will be relieved that the capital monster isn't really there
at all - sorry, my typo :-)
  
As for the rest, yes, that's what I did, but it's a bit more complicated
than you suggest. Presumably you only joined the list after this was
publicly thrashed out earlier this year; I'm sure you would have thrown
in your two cents' ;-) worth otherwise. 

This is the logic I ended up with, and successfully tested with GCC,
GPP, CFront and Norcroft C. I believe it should satisfy everyone, and
unless I've cocked it up monumentally (please tell me if you think I
have), I'll leave it as is; at this stage I certainly don't intend to
change it for reasons of style alone:

>From types.h:


/********************
 * Type definitions *
 ********************/
typedef unsigned int                            bits;
typedef int                                     osbool;
typedef unsigned char                           byte;

/* for backward compatibility with non C++ and pre-C99 code
** we can typedef |bool| as |osbool|. Anyone who wants to provide
** their own definition of |bool| can define BOOL_DEFINED prior to
** #includeing this header to prevent the typedef occurring.
*/

/* C99 defines bool as a keyword */
#if !defined BOOL_DEFINED && defined __STDC_VERSION__
  #if __STDC_VERSION__ >= 199901L
    #define BOOL_DEFINED
  #endif
#endif

/* C++ (1998) defines bool as a keyword;
** many implementations included it earlier,
** but there are some exceptions
*/
#if !defined BOOL_DEFINED && defined __cplusplus
  /* C++; Assume its's fully 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 previously */
  #if defined __CC_NORCROFT
    #undef BOOL_DEFINED
  #endif

  /* GNU C++ defines bool as a keyword only 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

#if !defined BOOL_DEFINED
   #define BOOL_IS_OSBOOL
   typedef osbool bool;
#endif

/************************
 * Constant definitions *
 ************************/
#ifndef NULL
#define NULL                                    0
#endif
#ifndef FALSE
#define FALSE                                   ((osbool) 0)
#endif
#ifndef TRUE
#define TRUE                                    ((osbool) 1)
#endif
...

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