C++ (Cross-Platform) Predefined Library

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.

Github Repos…


This content originally appeared on DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» and was authored by Maysara

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.

Github Repository

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

References


This content originally appeared on DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» and was authored by Maysara


Print Share Comment Cite Upload Translate Updates
APA

Maysara | Sciencx (2022-11-05T14:02:59+00:00) C++ (Cross-Platform) Predefined Library. Retrieved from https://www.scien.cx/2022/11/05/c-cross-platform-predefined-library/

MLA
" » C++ (Cross-Platform) Predefined Library." Maysara | Sciencx - Saturday November 5, 2022, https://www.scien.cx/2022/11/05/c-cross-platform-predefined-library/
HARVARD
Maysara | Sciencx Saturday November 5, 2022 » C++ (Cross-Platform) Predefined Library., viewed ,<https://www.scien.cx/2022/11/05/c-cross-platform-predefined-library/>
VANCOUVER
Maysara | Sciencx - » C++ (Cross-Platform) Predefined Library. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/11/05/c-cross-platform-predefined-library/
CHICAGO
" » C++ (Cross-Platform) Predefined Library." Maysara | Sciencx - Accessed . https://www.scien.cx/2022/11/05/c-cross-platform-predefined-library/
IEEE
" » C++ (Cross-Platform) Predefined Library." Maysara | Sciencx [Online]. Available: https://www.scien.cx/2022/11/05/c-cross-platform-predefined-library/. [Accessed: ]
rf:citation
» C++ (Cross-Platform) Predefined Library | Maysara | Sciencx | https://www.scien.cx/2022/11/05/c-cross-platform-predefined-library/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.