Component of the Week #7: bsls_platform
- Summary:
Provide a set of preprocessor macros that allow determining the properties of the target host platform at compile time.
When writing low-level system libraries, it is common to implement code paths that are specific to the compiler or target platform. The bsls_platform component provides a set of macros that allow the code to inspect many details about the compiler being used and the target hardware and operating system parameters at compile time.
The macros provided by this component can be split into three groups:
Operating system identification macros (
BSLS_PLATFORM_OS_*)Processor identification macros (
BSLS_PLATFORM_CPU_*)Compiler identification macros (
BSLS_PLATFORM_CMP_*)
#include <bsls_platform.h>
#include <bsl_iostream.h>
int main() {
bsl::cout << "This application was built for:\n";
#ifdef BSLS_PLATFORM_OS_LINUX
bsl::cout << "\n * Linux Operating system";
#else
#ifdef BSLS_PLATFORM_OS_UNIX
bsl::cout << "\n * Unix Operating system (non-Linux)";
#else
bsl::cout << "\n * Non-Unix Operating system";
#endif
#endif
#ifdef BSLS_PLATFORM_CMP_GNU
bsl::cout << "\n * With gcc GNU compiler v. " << BSLS_PLATFORM_CMP_VERSION;
#endif
#ifdef BSLS_PLATFORM_CPU_X86
bsl::cout << "\n * Target CPU: Intel x86 processor (32 bit mode)";
#endif
#ifdef BSLS_PLATFORM_CPU_X86_64
bsl::cout << "\n * Target CPU: Intel x86_64 processor (64 bit)";
#endif
}
- Check out the full documentation for
Happy coding!