1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 2<html> 3<head> 4<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"> 5<title>Chapter 29. Boost.Predef 1.10</title> 6<link rel="stylesheet" href="../../doc/src/boostbook.css" type="text/css"> 7<meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> 8<link rel="home" href="index.html" title="The Boost C++ Libraries BoostBook Documentation Subset"> 9<link rel="up" href="libraries.html" title="Part I. The Boost C++ Libraries (BoostBook Subset)"> 10<link rel="prev" href="poly_collection/acknowledgments.html" title="Acknowledgments"> 11<link rel="next" href="predef/using_the_predefs.html" title="Using the predefs"> 12</head> 13<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> 14<table cellpadding="2" width="100%"><tr> 15<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../boost.png"></td> 16<td align="center"><a href="../../index.html">Home</a></td> 17<td align="center"><a href="../../libs/libraries.htm">Libraries</a></td> 18<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> 19<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> 20<td align="center"><a href="../../more/index.htm">More</a></td> 21</tr></table> 22<hr> 23<div class="spirit-nav"> 24<a accesskey="p" href="poly_collection/acknowledgments.html"><img src="../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="libraries.html"><img src="../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="predef/using_the_predefs.html"><img src="../../doc/src/images/next.png" alt="Next"></a> 25</div> 26<div class="chapter"> 27<div class="titlepage"><div> 28<div><h2 class="title"> 29<a name="predef"></a>Chapter 29. Boost.Predef 1.10</h2></div> 30<div><div class="authorgroup"><div class="author"><h3 class="author"> 31<span class="firstname">Rene</span> <span class="surname">Rivera</span> 32</h3></div></div></div> 33<div><p class="copyright">Copyright © 2005-2019 Rene Rivera</p></div> 34<div><p class="copyright">Copyright © 2015 Charly Chevalier</p></div> 35<div><p class="copyright">Copyright © 2015 Joel Falcou</p></div> 36<div><div class="legalnotice"> 37<a name="predef.legal"></a><p> 38 Distributed under the Boost Software License, Version 1.0. (See accompanying 39 file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>) 40 </p> 41</div></div> 42</div></div> 43<div class="toc"> 44<p><b>Table of Contents</b></p> 45<dl class="toc"> 46<dt><span class="section"><a href="predef.html#predef.introduction">Introduction</a></span></dt> 47<dt><span class="section"><a href="predef/using_the_predefs.html">Using the predefs</a></span></dt> 48<dt><span class="section"><a href="predef/adding_new_predefs.html">Adding new predefs</a></span></dt> 49<dt><span class="section"><a href="predef/reference.html">Reference</a></span></dt> 50<dd><dl> 51<dt><span class="section"><a href="predef/reference.html#predef.reference.boost_arch_architecture_macros"><code class="computeroutput"><span class="identifier">BOOST_ARCH</span></code> architecture macros</a></span></dt> 52<dt><span class="section"><a href="predef/reference.html#predef.reference.boost_comp_compiler_macros"><code class="computeroutput"><span class="identifier">BOOST_COMP</span></code> compiler macros</a></span></dt> 53<dt><span class="section"><a href="predef/reference.html#predef.reference.boost_lang_language_standards_ma"><code class="computeroutput"><span class="identifier">BOOST_LANG</span></code> language standards macros</a></span></dt> 54<dt><span class="section"><a href="predef/reference.html#predef.reference.boost_lib_library_macros"><code class="computeroutput"><span class="identifier">BOOST_LIB</span></code> library macros</a></span></dt> 55<dt><span class="section"><a href="predef/reference.html#predef.reference.boost_os_operating_system_macros"><code class="computeroutput"><span class="identifier">BOOST_OS</span></code> operating system macros</a></span></dt> 56<dt><span class="section"><a href="predef/reference.html#predef.reference.boost_plat_platform_macros"><code class="computeroutput"><span class="identifier">BOOST_PLAT</span></code> platform macros</a></span></dt> 57<dt><span class="section"><a href="predef/reference.html#predef.reference.boost_hw_hardware_macros"><code class="computeroutput"><span class="identifier">BOOST_HW</span></code> hardware macros</a></span></dt> 58<dt><span class="section"><a href="predef/reference.html#predef.reference.other_macros">Other macros</a></span></dt> 59<dt><span class="section"><a href="predef/reference.html#predef.reference.version_definition_macros">Version definition 60 macros</a></span></dt> 61</dl></dd> 62<dt><span class="section"><a href="predef/check_utilities.html">Check Utilities</a></span></dt> 63<dt><span class="section"><a href="predef/history.html">History</a></span></dt> 64<dt><span class="section"><a href="predef/to_do.html">To Do</a></span></dt> 65<dt><span class="section"><a href="predef/acknoledgements.html">Acknoledgements</a></span></dt> 66</dl> 67</div> 68<div class="section"> 69<div class="titlepage"><div><div><h2 class="title" style="clear: both"> 70<a name="predef.introduction"></a><a class="link" href="predef.html#predef.introduction" title="Introduction">Introduction</a> 71</h2></div></div></div> 72<p> 73 This library defines a set of compiler, architecture, operating system, library, 74 and other version numbers from the information it can gather of C, C++, Objective 75 C, and Objective C++ predefined macros or those defined in generally available 76 headers. The idea for this library grew out of a proposal to extend the Boost 77 Config library to provide more, and consistent, information than the feature 78 definitions it supports. What follows is an edited version of that brief proposal. 79 </p> 80<h4> 81<a name="predef.introduction.h0"></a> 82 <span class="phrase"><a name="predef.introduction.proposal"></a></span><a class="link" href="predef.html#predef.introduction.proposal">Proposal</a> 83 </h4> 84<p> 85 The idea is to define a set of macros to identify compilers and consistently 86 represent their version. This includes: 87 </p> 88<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 89<li class="listitem"> 90 A unique BOOST_VERSION_NUMBER(major,minor,patch) macro to specify version 91 numbers (unfortunately, the name BOOST_VERSION is already taken to designate 92 the version number of boost itself). 93 </li> 94<li class="listitem"> 95 A compiler identification macro, suitable for use in <code class="computeroutput"><span class="preprocessor">#if</span></code>/<code class="computeroutput"><span class="preprocessor">#elif</span></code> directives, for each of the supported 96 compilers. All macros would be defined, regardless of the compiler. The 97 one macro corresponding to the compiler being used would be defined, in 98 terms of BOOST_VERSION_NUMBER, to carry the exact compiler version. All 99 other macros would expand to an expression evaluating to false (for instance, 100 the token 0) to indicate that the corresponding compiler is not present. 101 </li> 102<li class="listitem"> 103 "Null values" could be set, for all macros, in boost/config/select_compiler.hpp; 104 then, for each compiler the corresponding identification macro would be 105 #undef and re-#defined in the corresponding boost/compiler/(cc).hpp; however 106 in the context of the Boost.Config infrastructure using a "prefix" 107 header (to be introduced) or boost/config/suffix.hpp is a better solution. 108 </li> 109</ul></div> 110<h4> 111<a name="predef.introduction.h1"></a> 112 <span class="phrase"><a name="predef.introduction.current_library"></a></span><a class="link" href="predef.html#predef.introduction.current_library">Current 113 Library</a> 114 </h4> 115<p> 116 The current Predef library is now, both an independent library, and expanded 117 in scope. It includes detection and definition of architectures, compilers, 118 languages, libraries, operating systems, and endianness. The key benefits are: 119 </p> 120<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 121<li class="listitem"> 122 Version numbers that are always defined so that one doesn't have to guard 123 with <code class="computeroutput"><span class="preprocessor">#ifdef</span></code>. 124 </li> 125<li class="listitem"> 126 Guard macros that can be used for <code class="computeroutput"><span class="preprocessor">#ifdef</span></code> 127 checks. 128 </li> 129<li class="listitem"> 130 All possible definitions are included with the single <code class="computeroutput"><span class="preprocessor">#include</span> 131 <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">predef</span><span class="special">.</span><span class="identifier">h</span><span class="special">></span></code> 132 so that it's friendly to precompiled header usage. 133 </li> 134<li class="listitem"> 135 Specific definitions can be included, ex. <code class="computeroutput"><span class="preprocessor">#include</span> 136 <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">predef</span><span class="special">/</span><span class="identifier">os</span><span class="special">/</span><span class="identifier">windows</span><span class="special">.</span><span class="identifier">h</span><span class="special">></span></code> 137 for single checks. 138 </li> 139<li class="listitem"> 140 Predefs can be directly used in both preprocessor and compiler expressions 141 for comparison to other similarly defined values. 142 </li> 143<li class="listitem"> 144 The headers are usable from multiple languages, that support the C preprocessor. 145 In particular C++, C, Objective C, and Objective C++. 146 </li> 147</ul></div> 148<h4> 149<a name="predef.introduction.h2"></a> 150 <span class="phrase"><a name="predef.introduction.design_choices"></a></span><a class="link" href="predef.html#predef.introduction.design_choices">Design 151 choices</a> 152 </h4> 153<p> 154 An important design choice concerns how to represent compiler versions by means 155 of a single integer number suitable for use in preprocessing directives. Let's 156 do some calculation. The "basic" signed type for preprocessing constant-expressions 157 is long in C90 (and C++, as of 2006) and intmax_t in C99. The type long shall 158 at least be able to represent the number <code class="literal">+2 147 483 647</code>. 159 This means the most significant digit can only be 0, 1 or 2; and if we want 160 all decimal digits to be able to vary between 0 and 9, the largest range we 161 can consider is <code class="literal">[0, 999 999 999]</code>. Distributing evenly, this 162 means 3 decimal digits for each version number part. 163 </p> 164<p> 165 So we can: 166 </p> 167<div class="orderedlist"><ol class="orderedlist" type="1"> 168<li class="listitem"> 169 use an uneven distribution or 170 </li> 171<li class="listitem"> 172 use more bits (a larger type) or 173 </li> 174<li class="listitem"> 175 use 3/3/3 and have the particular compiler/platform/stdlib deal with setting 176 the numbers within the 3-digit range. 177 </li> 178</ol></div> 179<p> 180 It appears relatively safe to go for the first option and set it at 2/2/5. 181 That covers CodeWarrior and others, which are up to and past 10 for the major 182 number. Some compilers use the build number in lieu of the patch one; five 183 digits (which is already reached by VC++ 8) seems a reasonable limit even in 184 this case. 185 </p> 186<div class="note"><table border="0" summary="Note"> 187<tr> 188<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../doc/src/images/note.png"></td> 189<th align="left">Note</th> 190</tr> 191<tr><td align="left" valign="top"><p> 192 A 2/2/6 scheme would allow for bigger patch/build numbers at the cost, for 193 instance, of limiting the major version number to 20 (or, with further constraints, 194 to 21). 195 </p></td></tr> 196</table></div> 197<p> 198 It might reassure the reader that this decision is actually encoded in one 199 place in the code; the definition of <code class="computeroutput"><span class="identifier">BOOST_VERSION_NUMBER</span></code>. 200 </p> 201<h4> 202<a name="predef.introduction.h3"></a> 203 <span class="phrase"><a name="predef.introduction.future_work"></a></span><a class="link" href="predef.html#predef.introduction.future_work">Future 204 work</a> 205 </h4> 206<p> 207 Even though the basics of this library are done, there is much work that can 208 be done: 209 </p> 210<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 211<li class="listitem"> 212 Right now we limit the detection of libraries to known built-in predefined 213 macros, and to guaranteed to exist system and library headers. It might 214 be interesting to add something like auto-configuration predefs. This way 215 we can add definitions for user specific libraries and features. 216 </li> 217<li class="listitem"> 218 Along with the above, it might be good to add some user control as to which 219 headers are included with the top-level header. Although in the current 220 form of the library this is less of an issue as one can include the specific 221 headers one needs. 222 </li> 223<li class="listitem"> 224 Additionally, even if there is no auto-configure style option.. It would 225 be good to add optionally included headers so that user can get consistent 226 version number definitions for libraries they use. 227 </li> 228<li class="listitem"> 229 And obviously there's lots of work to do in reformulating the existing 230 Boost libraries to use the Predef library. 231 </li> 232<li class="listitem"> 233 And there's the continuing work of adding definitions for present and future 234 compilers, platforms, architectures, languages, and libraries. 235 </li> 236</ul></div> 237</div> 238</div> 239<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 240<td align="left"></td> 241<td align="right"><div class="copyright-footer"></div></td> 242</tr></table> 243<hr> 244<div class="spirit-nav"> 245<a accesskey="p" href="poly_collection/acknowledgments.html"><img src="../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="libraries.html"><img src="../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="predef/using_the_predefs.html"><img src="../../doc/src/images/next.png" alt="Next"></a> 246</div> 247</body> 248</html> 249