Skip to content

Preprocessor macros

DryPerspective edited this page Sep 28, 2023 · 6 revisions

A handful of macros are used in this project to selectively enable and disable code, depending on C++ version and platform. While this library conforms to the ISO C++98 standard, one of the compilers it was tested on does not; so some use of macros is needed to ensure smooth use of the library. This page will list them, whether they should be defined by the user, and what they do.

Macros the User Can Define

  • DP_CPPXX - Where XX is a C++ standard number (11, 14, 17, 20, or 23). These are used to disable code which was removed (note: not deprecated) between C++98 and the stated C++ standard. These are inclusive, so #define DP_CPP17 will selectively remove code which uses objects removed in C++11, C++14, and C++17. It is rare that you should need these, as use of future-removed features in this library will is rare, and this library should not be used in modern C++.

  • DP_NO_ASSERT_MACRO - If defined before including the static_assert header, the STATIC_ASSERT macro will not be defined. Note that the STATIC_ASSERT macro will not be transitively included by internal use of static assertions in this library, so this macro does not need to be used before including any other headers.

  • DP_NO_INCLUDE_BYTE - Suppresses inclusion of the byte header from within a certain testing header. This is to allow the library to be tested on systems where the assertion that sizeof(dp::byte) == 1 does not hold. Note that byte is not included in any other headers so this is not needed in normal code.

  • DP_BORLAND_USE_STD_EXCEPTIONS - Used to suppress exceptions inheriting from the C++Builder Exception class base on Borland compilers.

Automatically Defined Macros

  • DP_BORLAND - Defined automatically if the user is using a Borland compiler from before the days where Embarcadero updated from C++98 (circa 2018). Used to selectively disable parts of the code which that compiler is unable to process.

  • DP_CPPXX_OR_HIGHER - Used internally to selectively disable certain features which were removed in a particular C++ standard. Defined automatically when the user defines DP_CPPXX as a mechanism to allow inclusive changes (e.g. defining DP_CPP17 also disables features removed in C++11 and C++14)

  • STATIC_ASSERT - Defined automatically when including the static_assert header, unless it is suppressed be there already being a STATIC_ASSERT macro defined, or the user defining DP_NO_ASSERT_MACRO.

  • DP_BORLAND_EXCEPTIONS - Defined automatically if DP_BORLAND is defined and the user does not suppress the definition with DP_BORLAND_USE_STD_EXCEPTIONS. Used internally to make this library's exception types inherit from Borland's Exception type.

Clone this wiki locally