C++ Predefined Macros (Cross-Platform)
As we know there is no standard way in compilers to standardize macros with compilers and different operating systems
So I created this library that contains standardized macros and more.
Contents :
Architecture
This section contains some macros that can detect more than 20 architecture.Operating System
This section contains some macros that can detect more than 66 operating system.Compiler
This section contains some macros that can detect more than 75 compiler and its version.Library
This section contains some macros that can detect more than 11 library and its version.Standard
This section contains the standard macros more than 35 macro.Has Macros
This section contains the__has
macros more than 4 macros.Attributes
This section contains some standard and common attributes more than 13 attribute.Controllers
This section contains some macros that can manage some things in C/C++ more than 7 controllers.Helpers Macros
This section contains some macros that may be useful while writting this library.
Quick Examples
/* Print architecture name */
cout << X_ARCH << endl; // π "x86_64"
/* Check for specific architecture using ID/Macro */
#ifdef X_ARCH_<ID>
...
/* Print operating system name */
cout << X_OS << endl; // π "GNU/Linux"
/* Check for specific OS using ID/Macro */
#ifdef X_OS_<ID>
...
/* Print compiler info */
cout << X_COMP << endl; // π "GCC"
cout << X_COMP_MAJOR << endl; // π 12
cout << X_COMP_MINOR << endl; // π 1
cout << X_COMP_PATCH << endl; // π 0
cout << X_COMP_VERSION << endl; // π 201392128
cout << X_COMP_ORG_VERSION << endl; // π 12
/* Check for specific compiler using ID/Macro */
#ifdef X_COMP_<ID>
...
/* Print lib info */
cout << X_LIB << endl; // π "GNU glibc"
cout << X_LIB_MAJOR << endl; // π 2
cout << X_LIB_MINOR << endl; // π 35
cout << X_LIB_PATCH << endl; // π 0
cout << X_LIB_VERSION << endl; // π 35848192
cout << X_LIB_ORG_VERSION << endl; // π 2
/* Check for specific lib using ID/Macro */
#ifdef X_LIB_<ID>
...
/* Print some info */
cout << X_STD_CPP << endl; // π 20
cout << X_STD_FILE << endl; // π "path/main.cpp"
cout << X_STD_FUNC << endl; // π "main()"
cout << X_STD_LINE << endl; // π 4
cout << X_STD_TIME << endl; // π "10:19:16"
cout << X_STD_DATE << endl; // π "Oct 30 2022"
/* Check for specific Version */
#if X_STD_CPP >= 20 // you can use (X_STD_C) for c language
...
/* Check for Attribute */
#if X_HAS_ATTR(noreturn)
...
/* Check for Feature */
#if X_HAS_FEATURE(cxx_rvalue_references)
...
/* Check for Include */
#if X_HAS_INCLUDE("iostream")
...
/* Check for Builtin */
#if X_HAS_BUILTIN(__builtin_clz)
...
/* Usage of Attributes */
X_ATTR_DEPRECATED("old version")
X_ATTR_INLINE
X_ATTR_HIDDEN
void func(X_ATTR_MAYBE_UNUSED int i = 0)
...
/* Manage Exceptions */
X_CONSTEXPR void func() X_NOEXCEPT
// IF C++ && X_EXCEPTIONS => constexpr void func() noexcept
// ELSE => void func()
...
/* Throw An Exception */
X_THROW(exception);
// IF C++ && X_EXCEPTIONS => throw an exception
// ELSE IF C++ => assert an error with exception message
// ELSE => assert an error without message
/* Version Normalization (major, minor, patch) */
#define version X_VER(9,3,7)
Tests
This library has been tested on all of the following:
Operating System
-
Linux
Ubuntu 22.04.1 LTS -
Windows
Windows 10 pro
Compiler
-
GCC
12.1 -
Clang
15.0.0 -
MSVC
19.0
Top comments (0)