C++ use of bool
David J. Ruck
druck at freeuk.com
Fri May 5 18:13:04 BST 2000
On Fri 05 May, Tony van der Hoff wrote:
[#ifdef logic for determining bool keyword]
> If anyone has any better suggestions, I'd be pleased to hear them.
There is a way which avoids having know all the compiler versions, but is
somewhat nasty, and probably not suitable for the user base of OSLib.
When installing the library to automatically generate a header file using a
script and a small piece of code which is compiled by the target compiler.
The piece of code just determins the size of the bool keyword. There would
be three outcomes which would be picked up by the script:-
* doesn't compile - no bool keyword, so safe to typedef osbool bool
* compiles, runs, detects sizeof(bool)==4 - the bool keyword may be used
* compiles, runs, detects sizeof(bool)!=4 - warns user that using the bool
keyword provided by the compiler with OS_Lib is not safe
Ofcourse you need to know the name of the compiler which the user will be
using, so a script may not be sufficent and an interactive program would
be needed - thats where it gets nasty.
I've used this technique myself with multi-platform programs that need
to know the endianness of the processor and structure packing attributes
of the compiler. When porting to a new platform you run a small program
which generates a few #defines's which are then added to a header file
in a #ifdef block for that platform & compiler (which prevents an #error
being reached for unknown platforms).
Cheers
---Dave
--
______________________________________________________________________
David J. Ruck Phone: 07974 108301 Email: druck at freeuk.com
______________________________________________________________________
More information about the oslib-user
mailing list