Sane C++ Libraries
C++ Platform Abstraction Libraries
Compiler Macros

Compiler Macros Preprocessor macros to detect compiler and platform features. More...

Macros

#define SC_ASSERT_RELEASE(e)
 Assert expression e to be true. More...
 
#define SC_ASSERT_DEBUG(e)   (void)0
 Assert expression e to be true. More...
 
#define SC_COMPILER_CLANG   0
 Flag indicating Clang compiler. More...
 
#define SC_COMPILER_GCC   1
 Flag indicating GCC compiler. More...
 
#define SC_COMPILER_MSVC   0
 Flag indicating MSVC compiler. More...
 
#define SC_COMPILER_CLANG_CL   0
 Flag indicating non-Clang-CL (MSVC) compiler. More...
 
#define SC_COMPILER_FORCE_INLINE   __attribute__((always_inline)) inline
 Macro for forcing inline functions. More...
 
#define SC_COMPILER_EXTERN
 Define compiler-specific export macros for DLL visibility. More...
 
#define SC_COMPILER_EXPORT    __attribute__((visibility("default")))
 Macro for symbol visibility in non-MSVC compilers. More...
 
#define SC_COMPILER_ASAN   0
 Evaluates to true (1) if ASAN is active. More...
 
#define SC_COMPILER_WARNING_POP   _Pragma("warning(pop)")
 Pops warning from inside a macro. More...
 
#define SC_COMPILER_OFFSETOF(Class, Field)   __builtin_offsetof(Class, Field)
 Returns offset of Class::Field in bytes. More...
 
#define SC_COMPILER_FIELD_OFFSET(Class, Field, Value)    SC::fieldOffset<SC_COMPILER_OFFSETOF(Class, Field), Class, decltype(Class::Field)>(Value);
 
#define SC_COMPILER_WARNING_PUSH_OFFSETOF
 Disables invalid-offsetof gcc and clang warning. More...
 
#define SC_COMPILER_UNUSED(param)   ((void)param)
 Silence an unused variable or unused parameter warning. More...
 
#define SC_COMPILER_WARNING_PUSH_UNUSED_RESULT    _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wunused-result\"")
 Disables unused-result warning (due to ignoring a return value marked as [[nodiscard]]) More...
 
#define SC_LANGUAGE_CPP_VERSION   __cplusplus
 SC_LANGUAGE_FORCE_STANDARD_CPP == 14, 17 or 20 to force a specific C++ standard version (202002L, 201703L or 201402L) More...
 
#define SC_LANGUAGE_CPP_LESS_THAN_20   1
 True (1) if C++ standard is < C++ 20. More...
 
#define SC_LANGUAGE_CPP_AT_LEAST_20   0
 True (1) if C++ standard is <= C++ 20. More...
 
#define SC_LANGUAGE_CPP_AT_LEAST_17   0
 True (1) if C++ standard is <= C++ 17. More...
 
#define SC_LANGUAGE_CPP_AT_LEAST_14   0
 True (1) if C++ standard is <= C++ 14. More...
 
#define SC_LANGUAGE_LIKELY
 
#define SC_LANGUAGE_UNLIKELY
 
#define SC_LANGUAGE_IF_CONSTEXPR
 
#define SC_LANGUAGE_EXCEPTIONS   0
 
#define SC_LANGUAGE_LIFETIME_BOUND
 
#define SC_CONFIGURATION_DEBUG   0
 True (1) if debug configuration is active (_DEBUG==1 or DEBUG==1) More...
 
#define SC_CONFIGURATION_RELEASE   1
 True (1) if release configuration is active (!(_DEBUG==1 or DEBUG==1)) More...
 

Detailed Description

Compiler Macros Preprocessor macros to detect compiler and platform features.

Macro Definition Documentation

◆ SC_ASSERT_DEBUG

#define SC_ASSERT_DEBUG (   e)    (void)0

#include <Assert.h>

Assert expression e to be true.

If Failed, prints the failed assertion with backtrace, breaks debugger and exits (-1). Only active under SC_CONFIGURATION_DEBUG configuration, and defined to empty otherwise

◆ SC_ASSERT_RELEASE

#define SC_ASSERT_RELEASE (   e)

#include <Assert.h>

Value:
if (!(e)) \
SC_LANGUAGE_UNLIKELY \
{ \
SC::Assert::print(#e, __FILE__, __func__, __LINE__); \
SC_COMPILER_DEBUG_BREAK; \
} \
(void)0
static void exit(int code)
Exits current process.
static bool printBacktrace()
Prints backtrace (call stack) of the caller to standard output.
static void print(const char *expression, const char *filename, const char *functionName, int lineNumber)
Prints an assertion to standard output.

Assert expression e to be true.

If Failed, prints the failed assertion with backtrace, breaks debugger and exits (-1)

◆ SC_COMPILER_ASAN

#define SC_COMPILER_ASAN   0

#include <Compiler.h>

Evaluates to true (1) if ASAN is active.

Flag indicating the absence of Address Sanitizer (ASAN).

◆ SC_COMPILER_CLANG

#define SC_COMPILER_CLANG   0

#include <Compiler.h>

Flag indicating Clang compiler.

◆ SC_COMPILER_CLANG_CL

#define SC_COMPILER_CLANG_CL   0

#include <Compiler.h>

Flag indicating non-Clang-CL (MSVC) compiler.

◆ SC_COMPILER_EXPORT

#define SC_COMPILER_EXPORT    __attribute__((visibility("default")))

#include <Compiler.h>

Macro for symbol visibility in non-MSVC compilers.

◆ SC_COMPILER_EXTERN

#define SC_COMPILER_EXTERN

#include <Compiler.h>

Define compiler-specific export macros for DLL visibility.

◆ SC_COMPILER_FORCE_INLINE

#define SC_COMPILER_FORCE_INLINE   __attribute__((always_inline)) inline

#include <Compiler.h>

Macro for forcing inline functions.

◆ SC_COMPILER_GCC

#define SC_COMPILER_GCC   1

#include <Compiler.h>

Flag indicating GCC compiler.

◆ SC_COMPILER_MSVC

#define SC_COMPILER_MSVC   0

#include <Compiler.h>

Flag indicating MSVC compiler.

◆ SC_COMPILER_OFFSETOF

#define SC_COMPILER_OFFSETOF (   Class,
  Field 
)    __builtin_offsetof(Class, Field)

#include <Compiler.h>

Returns offset of Class::Field in bytes.

◆ SC_COMPILER_UNUSED

#define SC_COMPILER_UNUSED (   param)    ((void)param)

#include <Compiler.h>

Silence an unused variable or unused parameter warning.

◆ SC_COMPILER_WARNING_POP

#define SC_COMPILER_WARNING_POP   _Pragma("warning(pop)")

#include <Compiler.h>

Pops warning from inside a macro.

◆ SC_COMPILER_WARNING_PUSH_OFFSETOF

#define SC_COMPILER_WARNING_PUSH_OFFSETOF

#include <Compiler.h>

Value:
_Pragma("GCC diagnostic push"); \
_Pragma("GCC diagnostic ignored \"-Winvalid-offsetof\"");

Disables invalid-offsetof gcc and clang warning.

◆ SC_COMPILER_WARNING_PUSH_UNUSED_RESULT

#define SC_COMPILER_WARNING_PUSH_UNUSED_RESULT    _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wunused-result\"")

#include <Compiler.h>

Disables unused-result warning (due to ignoring a return value marked as [[nodiscard]])

◆ SC_CONFIGURATION_DEBUG

#define SC_CONFIGURATION_DEBUG   0

#include <Platform.h>

True (1) if debug configuration is active (_DEBUG==1 or DEBUG==1)

◆ SC_CONFIGURATION_RELEASE

#define SC_CONFIGURATION_RELEASE   1

#include <Platform.h>

True (1) if release configuration is active (!(_DEBUG==1 or DEBUG==1))

◆ SC_LANGUAGE_CPP_AT_LEAST_14

#define SC_LANGUAGE_CPP_AT_LEAST_14   0

#include <Compiler.h>

True (1) if C++ standard is <= C++ 14.

◆ SC_LANGUAGE_CPP_AT_LEAST_17

#define SC_LANGUAGE_CPP_AT_LEAST_17   0

#include <Compiler.h>

True (1) if C++ standard is <= C++ 17.

◆ SC_LANGUAGE_CPP_AT_LEAST_20

#define SC_LANGUAGE_CPP_AT_LEAST_20   0

#include <Compiler.h>

True (1) if C++ standard is <= C++ 20.

◆ SC_LANGUAGE_CPP_LESS_THAN_20

#define SC_LANGUAGE_CPP_LESS_THAN_20   1

#include <Compiler.h>

True (1) if C++ standard is < C++ 20.

◆ SC_LANGUAGE_CPP_VERSION

#define SC_LANGUAGE_CPP_VERSION   __cplusplus

#include <Compiler.h>

SC_LANGUAGE_FORCE_STANDARD_CPP == 14, 17 or 20 to force a specific C++ standard version (202002L, 201703L or 201402L)

Macro to check __cplusplus properly on MSVC