Skip to content

CrackerCat/cpp-predefined

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

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 built-in functions 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.

  • Builtin
    This section contains some cross-platform builtin functions more than 4 functions.

  • 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_compiler                << endl; // 👉 "GCC"
    cout << x_compiler_major          << endl; // 👉 12
    cout << x_compiler_minor          << endl; // 👉 1
    cout << x_compiler_patch          << endl; // 👉 0
    cout << x_compiler_version        << endl; // 👉 201392128
    cout << x_compiler_org_version    << endl; // 👉 12
    
    /*         Check for specific compiler using ID/Macro         */
    #ifdef x_compiler_<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
  • /*                      Usage of Builtin                      */
    cout << x_builtin_clz  (987654321) << endl; // 👉 2
    cout << x_builtin_clzll(987654321) << endl; // 👉 34
    cout << x_builtin_ctz  (987654321) << endl; // 👉 0
    cout << x_builtin_ctzll(987654321) << endl; // 👉 0
  • /*                      C/C++ Static Cast                     */
    int var = x_scast(int, 0);
    
    /*        Version Normalization (major, minor, patch)         */
    #define version x_ver(9,3,7)
    
    /*        Check whether the language used is cpp or not       */
    #if x_is_cpp
    ...

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

About Syntax

All macro names in this library follow the following syntax: prefix section|name ID for example x_os_LINUX

  • x_ is the prefix and shortcut for xeerx_.
  • os is the section name.
  • _LINUX is the id it must be capitalized.

This library is part of the xeerx project but I hope it will be useful to someone.


References

About

C++ Cross-Platform Predefined Macros

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 93.0%
  • C++ 7.0%