Boost logo

Boost Users :

From: Jim.Hyslop (jim.hyslop_at_[hidden])
Date: 2002-11-14 15:13:33


Sam Gentile [mailto:ManagedCode_at_[hidden]] wrote:
> Well at least you gave somewhat of an answer. I still want to
> understand
> how those particular macros give that portability.
I haven't looked at the macros in question, but one approach to portability
is to separate the macro definitions into platform-specific files. Exactly
which file gets included depends on the compiler settings. For example:

// file: compilerX/defines.h
[omitting include guards for brevity
#define DO_SOMETHING(x) CallCompilerXFn( x )

// end file

// file: compilerY/defines.h
#define DO_SOMETHING(x) compiler_y_function( x )

// end file

// file: some Boost header
#include "defines.h"

class someClass
{
   void f(T a) { DO_SOMETHING( a ); }
};

Exactly _which_ "defines.h" gets included is controlled by the build
settings, which are determined by the platform.

The alternative is a really ugly set of #ifdefs:

// file: some Boost header
class someClass
{
   void f(T a)
   {
#ifdef COMPILER_X
      CallCompilerXFn( a );
#elif defined(COMPILER_Y)
      compiler_y_function( a );
[... etc. for each platform supported
#endif
   }
};

As I said, that's _one_ approach - Boost uses something slightly different.
Have a look at config.hpp to see its approach.

-- 
Jim

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net