Introduction To Cross-Platform Macros

There are currently three target environments that the YAAF libraries can be compiled under. Further, there are several different configurations possible for each of these target environments. In order to provide both the YAAF library and applications built on top of the YAAF library to know what type of environment it is being compiled under, use conditional compilation and the differently defined macros defined in <XConfig.h>.

Using The Cross-Platform Macros

Depending on the target platform, the macros in <XConfig.h> are conditionally compiled to specify the type of environment the YAAF libraries are being compiled under. How this is done depends on if the code is being compiled on the Macintosh, on Microsoft Windows, or on Unix, and on the compiler used.

> Macintosh Compilation

> On the Macintosh, the YAAF libraries are compiled using the Metrowerks Codewarrior C++ compiler. This compiler defines the following macros which is then used by <XConfig.h> :

> __MWERKS__ | Defined if the code is being compiled on the Metrowerks Codewarrior environment
> macintosh | Defined if the code is being compiled using the Metrowerks Codewarrior compiler for the Macintosh
> __INTEL__ | Defined if the code is being compiled using the Metrowerks Codwarrior compiler for the Intel processor. It is assumed that if we are compiling using the Intel processor, we're compiling for Widnows 95 or Windows NT.

> Microsoft Visual C++ Compilation

> If we are compiling on Microsoft Visual C++, we use the following macros (which are defined by default) in order to determine what is going on:

> WIN32 | Defined by default in Microsoft Visual C++ when the code is being compiled for Microsoft Windows 95/98 or Windows NT.

> Unix Compilation

> On Unix, we do not assume the compiler predefines any symbols. Instead, we assume that in the Makefile, the following symbols are defined at the compiler's command line arguments (by using the -Dxxx switch):

> OPT_XWIN = 1 | Indicates the YAAF library is being compiled to work with X on Unix.
> OPT_NATIVEORDER | Defined as 1 if the order of bytes in an integer is in network-native order, or 0 if they are not.

> Other Compilers

> If you are planning to port the YAAF libraries to another platform, you will need to modify the definitions in <XConfig.h> to properly define the macros described in the next section. This means either determining from compiler-specific macros the type of environment you are compiling under, or setting the macros yourself.

Other Files Included by <XConfig.h>

To minimize porting considerations when writing a YAAF application, the <XConfig.h> header also includes the following files, depending on what target environment the code is being compiled under:

> Macintosh | On the Macintosh, no additional files are included. It is assumed that the default precompiled headers from Metrowerks Codewarrior are included; these include the core MacOS headers for windows, controls, cursors, QuickDraw, and the like.
> Microsoft Windows | Includes <Windows.h>, the main Microsoft Windows header. If you are using Visual C++ to compile your program, you can speed up compilation by placing <XConfig.h> before any other header files, and using the "precompiled headers" setting.
> X on Unix | Includes <g++/std/typeinfo.h>. The YAAF libraries use both exceptions and RTTI to operate, and on some environments I have compiled under, the GNU C++ compiler complains that <typeinfo> is missing. Yes, this is a bit of a kludge, I suppose.

Cross-Platform Macro Definitions

> OPT_MACOS = 0 or 1
> OPT_WINOS = 0 or 1
> OPT_XWIN = 0 or 1

> One of the above macros are defined as 1, and the other two are defined as 0, when the YAAF libraries are compiled on a particular environment (either the Macintosh, Microsoft Windows, or X). To test which environment your software is being compiled under, use the following C preprocessor statement:

> >     #if OPT_MACOS == 1
> >     ...
> >     #endif // OPT_MACOS == 1

> OPT_NATIVEORDER = 0 or 1

> This indicates if the target environment's byte order is either network native or not. (For reference, the Macintosh uses network-native byte ordering, while Microsoft Windows does not.) This is used extensively by the Data Utilities, and if you use the byte swaping macros defined there, you will not have to worry about this macro's setting.