BOOL in Systypes.h
Erik Groenhuis
e.groenhuis at xs4all.nl
Wed Dec 24 10:42:37 GMT 2003
Spoke too soon.
As Erik Groenhuis <e.groenhuis at xs4all.nl> wrote:
> Systypes.h in OSLibSupport does it's own definition of BOOL (and NULL):
>
> ------8<------------
> #if !defined BOOL
> #define BOOL bool
> #endif
>
> #if !defined NULL
> #define NULL ((void*)0)
> #endif
> ------8<------------
>
> This is unwise, as there is a very good definition of BOOL in
> oslib/types.h, which takes into account various compilers.
oslib/types.h does not define BOOL. It defines BOOL_DEFINED, and if
needed does a
typedef osbool bool;
The reason I hit problems is because the !Dustbin example uses BOOL as
if it is a defined type:
====== main.h ======
void Main_SetIconFull( BOOL bTrue );
====================
while there is no definition in the headers, except for the one
mentioned above, and in oslib/macros.h, where it is defined as:
====== macros.h ========
/* ------------------------------------------------------------------------
* Macro: BOOL()
*
* Description: Converts non-0 values to 1
*/
#define BOOL(c) ((c) != 0? TRUE: FALSE)
========================
This conflicts with Systypes.h *and* is unneccesary. Instead of the
BOOL(x) the programmer can simply write (!!x) or (TRUE && x), and the
compiler will convert from zero/nonzero to zero/-1.
So the chain goes like this:
In the !Dustbin example, main.h uses BOOL.
BOOL is #defined in Systypes.h as bool.
oslib/types.h ensures bool is typedef-ed.
(In my Norcroft C99 compiler, bool is typedef-ed in C:stdbool.h).
My remaining gripe is now with oslib/macros.h. The macro def there
prevents a succesful compilation of the !Dustbin example.
--
Erik Groenhuis http://www.xs4all.nl/~erikgrnh
Home of RCS for RISC OS v5.7.1.2 http://www.rcs.riscos.org.uk/
Csite on RiscPC with a StrongARM RISC processor and RISC OS 4.02
More information about the oslib-user
mailing list