Artifact 1642ff4e434f6fa7d63b8b52c3c21b2b030c8a06:

Wiki page [BehaviourMacros] by luismachuca 2017-08-11 17:40:15.
D 2017-08-11T17:40:15.429
L BehaviourMacros
P 01537d87a6fc3da7195c0e62988a3deabacc5ba4
U luismachuca
W 7634
<h2>Basic Macros</h2>

When this library is included in a piece of software, the following macros are defined:

  *  <code>CXXOMFORT_DATE</code> - it expands to an unsigned integer representing the release date of the current version in the format <em>YYYYMM</em>.
  *  <code>CXXOMFORT_CXX_STD</code> - resolves to a numeric value indicating the Standard version supported by the compiler, for example <code>2011</code> for C++11-compliant compilers.
  *  <code>CXXOMFORT_CXX_EMULATION</code> - resolves to a numeric value that corresponds the Standard version that the compiler is emulating, if it is operating in an "emulation" mode such as GCC's c++0x.
  *  <code>CXXOMFORT_COMPILER_ID</code> - this expands to a numerical code identifying the compiler, if it has been identified.
  *  <code>CXXOMFORT_COMPILER_VERSION</code> - this expands to a numerical code identifying the compiler version, using the format <code>100*major+minor</code> where possible.

The following macros exist and deliver information but are to be <b>deprecated</b> in a future version:

  *  <code>CXXOMFORT_VERSION</code> - it expands to an unsigned integer representing the library version with the formula <em>100*major+minor</em>.


<h2>Configuration Macros</h2>

The behaviour of this library can be queried or configured via a set of macros.


The following macros can be used to change the behaviour of this library:

  *  <code>CXXOMFORT_NOTICES</code> - if defined and nonzero, the library will emit some diagnostics indicating what features are being used, etc. These diagnostics do not affect the code being compiled and are only informative. The higher the value of the macro, the more diagnostics does the library emit.
  *  <code>CXXOMFORT_NO_TR1</code> - if defined, the library will not <code>#include</code> some of the headers required for TR1 features. Note that this configuration is not supported, after all part of the purpose of this library is to make those features usable.

Diagnostics emitted by <code>CXXOMFORT_NOTICES</code>

<table>
<tr><td><code> == 1</code></td><td>Emits basic library identification messages.<br/>Emits standard vs emulation notice.<br/>Emits a message when an "Extra" feature is included.</td>
</tr>
<tr><td><code> == 2</code></td><td>Emits compiler identification messages related to patches.<br/>Emits notification when additions to TR1 library headers (<functional>, <tuple>, etc...) are included.</td>
</tr>
<tr><td><code> == 3</code></td><td>Emits notifications of all features being included.</br>Emits patching diagnostics.</td>
</tr>
</table>

<h2>"Standard Mode" and "Emulation Mode"</h2>

This library attempts to detect when the compiler supports the C++98/03, C++11 or C++14 Standard and is using its features, in which case it sets the value of the macro <b><code>CXXOMFORT_CXX_STD</b></code> to the given year (1998, 2011 or 2014) for use. 

Identification of <b>C++11 Mode</b> relies in the Standard-specified method of announcing compliance - that is, by defining the identifier <code>__cplusplus</code> to an adequate value.


In some environments, the library can also detect if the compiler is operating in a C++11 or C++14 "emulation" mode, usually called "<i>C++0x</i>", "<i>c++1y</i>" or the like, where only a subset of features is implemented and/or they are done only partially. If such emulation mode is detected, the macro <code>CXXOMFORT_CXX_EMULATION</code> takes the value of the given year of the standard emulated.

Identification of <b>Emulation Mode</b> is a compiler-dependent and project-dependent feature, so this method is not exact. For a compiler to be recognized as operating in C++11 mode, for example, the following need to hapen:

<ul><li>The compiler advertises C++11 emulation mode by defining a particular macro (for example <code>GNUXX_EXPERIMENTAL_CXX0X</code> in GCC).
</li>
</ul>

<b>Values of the control macros under different settings</b>:

<table>
<tr><th>Build Setup      </th><th>Compiler and Version </th><th> CXX_STD</th><th> CXX_EMULATION </th></tr>
<tr>
<th>GCC 4.6, --std=c++03 </th><td>  <code>101</code> <code>0406</code>  </td><td>  <code>1997</code>  </td><td>  <code>   0</code>  </td>
</tr><tr>
<th>GCC 4.6, --std=c++0x </th><td>  <code>101</code> <code>0406</code>  </td><td>  <code>1997</code>  </td><td>  <code>2011</code>  </td>
</tr><tr>
<td>GCC 4.4, no --std flag</td><td>   <code>101</code> <code>0404</code>  </td><td>  <code>1997</code>  </td><td>  <code>   0</code>  </td>
</tr><tr>
<td>GCC 4.4, --std=c++0x </td><td>  <code>101</code> <code>0404</code>  </td><td>  <code>1997</code>  </td><td>  <code>2011</code>  </td>
</tr><tr>
<td>GCC 4.8, --std=c++03    </td><td> <code>101</code> <code>0408</code>  </td><td>  <code>1997</code>  </td><td>  <code>   0</code>  </td>
</tr><tr>
<td>GCC 4.8, --std=c++11  </td><td> <code>101</code> <code>0408</code>  </td><td>  <code>2011</code>  </td><td>  <code>2011</code>  </td>
</tr><tr>
<th>MSVC 2010 </th><td>     <code>103</code> <code>0160</code>  </td><td>  <code>1997</code>  </td><td> <code>2011</code>  </td>
</tr><tr>
<td>MSVC 2008 SP1 </td><td>     <code>103</code> <code>0150</code>  </td><td>  <code>1997</code>  </td><td> <code>   0</code>  </td>
</tr><tr>
<td>MSVC 2015 C++ Build Tools</td><td> N/A </td>
</tr><tr>
<td>Clang 3.4, --std=c++03 </td><td> <code>104</code> <code>0304</code>  </td><td>  <code>1997</code>  </td><td>  <code>   0</code>  </td>
</tr><tr>
<td>Clang 3.4, --std=c++11 </td><td> <code>104</code> <code>0304</code>  </td><td>  <code>2011</code>  </td><td>  <code>   0</code>  </td>
</tr><tr>
<td> Clang 3.2</td><td> N/A </td>
</tr><tr>
<td> Open Watcom </td><td> N/A </td>
</tr><tr>
</tr>
</table>


The library also sets a number of macros to determine what features are found as supported by the compiler in either Standard or Emulation mode:

<table>
<tr><th>Macro</th><th>Nonzero if...</th></tr>
<tr>
<td>CXXO_COMPILER_SUPPORT_attribute</td><td><code><nowiki>[[attribute]]</nowiki></code> is supported</td>
</tr><tr>
<td>CXXO_COMPILER_SUPPORT_auto</td><td>C++11 type-deducing semantics for 'auto' is supported</td>
</tr><tr>
<td>CXXO_COMPILER_SUPPORT_constexpr</td><td>'constexpr' is supported</td>
</tr><tr>
<td>CXXO_COMPILER_SUPPORT_decltype</td><td>'decltype' is supported</td>
</tr><tr>
<td>CXXO_COMPILER_SUPPORT_default_delete</td><td>C++11 "=default" and "=delete" for members is supported</td>
</tr><tr>
<td>CXXO_COMPILER_SUPPORT_foreach</td><td>C++11 'for(i: range)' syntax is supported</td>
</tr><tr>
<td>CXXO_COMPILER_SUPPORT_local_types</td><td>C++11 locally defined types as arguments for templates is supported</td>
</tr><tr>
<td>CXXO_COMPILER_SUPPORT_noexcept</td><td>C++11 'noexcept' is supported</td>
</tr><tr>
<td>CXXO_COMPILER_SUPPORT_rvref</td><td>C++11 rvalue-references (T&&) is supported</td>
</tr><tr>
<td>CXXO_COMPILER_SUPPORT_variadic</td><td>C++11 variadic template arguments is supported</td>
</tr></table>

The library also provides the ability to write <b>conditional code</b> depending on the detected C++ version:

  *  <code>CXXOMFORT_CXX11_CODE(cxx11,cxx03)</code> - this macro allows to write small snippets of code, such as keywords, [Conditional Code|conditioned to operating in C++11 onwards or C++03 mode].
  *  <code>CXXOMFORT_CXX14_CODE(cxx14,cxx01)</code> - this macro allows to write small snippets of code, such as keywords, [Conditional Code|conditioned to operating in C++14 onwards or C++11 backwards mode].



<hr>

  *  [Configuration]
  *  [Cxxomfort|Back to the beginning]

Z 70109c9a81cc723d87a9c452c412c446