RE: [Boost-Users] A strange question-)

Sam Gentile [mailto:ManagedCode@attbi.com] 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
participants (1)
-
Jim.Hyslop