BDE 4.14.0 Production release
|
Macros | |
#define | BSLS_PLATFORM_COMPILER_ERROR char die[sizeof(bsls_Platform_Assert)] |
#define | BSLS_PLATFORM_AGGRESSIVE_INLINE inline |
#define | BSLS_PLATFORM_OS_SUBTYPE_COUNT |
Variables | |
BSLS_PLATFORM_COMPILER_ERROR | |
Provide compile-time support for platform/attribute identification.
This component implements a suite of preprocessor macros and traits that identify and define platform-specific compile-time attributes. These attributes consist of the types and versions of (1) the operating system, (2) the processor(s), and (3) the compiler that together make up the platform. Many of the macros defined in this component are configured automatically at compile-time; compile-time switches are used to configure the rest. Note that compiler capabilities are better determined through the bsls_compilerfeatures and bsls_libraryfeatures components; this component focuses on just identifying the tool chain.
Note that, for brevity, the @
character in the following (alphabetically organized) tables is used to represent the characters BSLS_PLATFORM
– e.g., @_OS_UNIX
represents BSLS_PLATFORM_OS_UNIX
:
These macros are configured automatically, where possible. At a minimum, the generic operating system type (i.e., either BSLS_PLATFORM_OS_UNIX
or BSLS_PLATFORM_OS_WINDOWS
) is defined along with exactly one processor macro (e.g., BSLS_PLATFORM_CPU_SPARC
) and exactly one compiler macro (e.g., BSLS_PLATFORM_CMP_SUN
). Clients may need to supply additional macros (controlled via the -D
option of a compiler) if further discrimination is required (e.g., based on sub-type or version of a specific operating system, processor, or compiler). Note that supplying a minor version number implies that the major version is also defined.
The aggressive inlining macro BSLS_PLATFORM_AGGRESSIVE_INLINE
is defined as the inline
keyword on all compilers except BSLS_PLATFORM_CMP_IBM
and BSLS_PLATFORM_CMP_SUN
, where it is left empty. This is required for some of our legacy applications where substantially growing the text size is not possible. Even on those platforms, the symbol will be defined as inline
if BDE_BUILD_TARGET_AGGRESSIVE_INLINE
is passed in via the -D
option of the compiler.
The compiler-error triggering macro BSLS_PLATFORM_COMPILER_ERROR
is defined to a sequence of tokens that guarantees a compilation error on every supported compiler. This is necessary because not all compilers will respect the fairly obvious goal of the #error
preprocessor directive even though they support it, and just issue a warning (claiming that the C++ standard does not make a difference between a warning and an error, it knows only about diagnostic messages). Code using bsls_platform macros will often want to prevent compilation for unsupported platforms, hence this component provides a macro that can be used to ensure that.
Windows Subtypes describe what API variation the code is built to target, not the actual operating system it will run on, with the following mapping between the macro names and Windows API versions:
Note that Vista is the default targeted API.
Writing portable software sometimes involves specializing implementations to work with platform-specific interfaces. For example, a socket-level communications framework would need to operate differently on a platform having a Windows operating system than on one having a Unix one (but it is probably unnecessary to distinguish between their respective versions):
Certain compile-time constants are also provided as preprocessor macros that encapsulate the capability of determining whether a machine is big-endian or little-endian across all supported platforms:
These macros are useful for writing platform-independent code, such as a function that converts the bytes in a short
to network byte order (which is consistent with big-endian):
#define BSLS_PLATFORM_AGGRESSIVE_INLINE inline |
#define BSLS_PLATFORM_COMPILER_ERROR char die[sizeof(bsls_Platform_Assert)] |
#define BSLS_PLATFORM_OS_SUBTYPE_COUNT |
BSLS_PLATFORM_COMPILER_ERROR |
Implementation Note