• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4<title>cpp&lt;int C, int S, int I, int L, int LL&gt;</title>
5<link rel="stylesheet" href="../boostbook.css" type="text/css">
6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
7<link rel="home" href="../index.html" title="Safe Numerics">
8<link rel="up" href="../promotion_policies.html" title="Promotion Policies">
9<link rel="prev" href="automatic.html" title="automatic">
10<link rel="next" href="../exception_safety.html" title="Exception Safety">
11</head>
12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13<table cellpadding="2" width="100%"><tr>
14<td valign="top"><img href="index.html" height="164px" src="pre-boost.jpg" alt="Library Documentation Index"></td>
15<td><h2>Safe Numerics</h2></td>
16</tr></table>
17<div class="spirit-nav">
18<a accesskey="p" href="automatic.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../promotion_policies.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="../exception_safety.html"><img src="../images/next.png" alt="Next"></a>
19</div>
20<div class="section">
21<div class="titlepage"><div><div><h4 class="title">
22<a name="safe_numerics.promotion_policies.cpp"></a>cpp&lt;int C, int S, int I, int L, int LL&gt;</h4></div></div></div>
23<div class="section">
24<div class="titlepage"><div><div><h5 class="title">
25<a name="idm130202658416"></a>Description</h5></div></div></div>
26<p>This policy is used to promote safe types in arithmetic expressions
27    according to the rules in the C++ standard. But rather than using the
28    native C++ standard types supported by the compiler, it uses types whose
29    length in number of bits is specified by the template parameters.</p>
30<p>This policy is useful for running test programs which use C++
31    portable integer types but which are destined to run on an architecture
32    which is different than the one on which the test program is being built
33    and run. This can happen when developing code for embedded systems.
34    Algorithms developed or borrowed from one architecture but destined for
35    another can be tested on the desktop.</p>
36<p>Note that this policy is only applicable to safe types whose base
37    type is a type fulfilling the type requirements of <a class="link" href="integer.html" title="Integer&lt;T&gt;">Integer</a>.</p>
38</div>
39<div class="section">
40<div class="titlepage"><div><div><h5 class="title">
41<a name="idm130202654880"></a>Template Parameters</h5></div></div></div>
42<div class="informaltable"><table class="table">
43<colgroup>
44<col align="left">
45<col align="left">
46<col align="left">
47</colgroup>
48<thead><tr>
49<th align="left">Parameter</th>
50<th align="left">Type</th>
51<th align="left">Description</th>
52</tr></thead>
53<tbody>
54<tr>
55<td align="left"><code class="computeroutput">C</code></td>
56<td align="left">int</td>
57<td align="left">Number of bits in a char</td>
58</tr>
59<tr>
60<td align="left"><code class="computeroutput">S</code></td>
61<td align="left">int</td>
62<td align="left">Number of bits in a short</td>
63</tr>
64<tr>
65<td align="left"><code class="computeroutput">I</code></td>
66<td align="left">int</td>
67<td align="left">Number of bits in an integer</td>
68</tr>
69<tr>
70<td align="left"><code class="computeroutput">L</code></td>
71<td align="left">int</td>
72<td align="left">Number of bits in a long</td>
73</tr>
74<tr>
75<td align="left"><code class="computeroutput">LL</code></td>
76<td align="left">int</td>
77<td align="left">Number of bits in a long long</td>
78</tr>
79</tbody>
80</table></div>
81</div>
82<div class="section">
83<div class="titlepage"><div><div><h5 class="title">
84<a name="idm130202637904"></a>Model of</h5></div></div></div>
85<p><a class="link" href="promotion_policy.html" title="PromotionPolicy&lt;PP&gt;">PromotionPolicy</a></p>
86</div>
87<div class="section">
88<div class="titlepage"><div><div><h5 class="title">
89<a name="idm130202636192"></a>Example of Use</h5></div></div></div>
90<p>Consider the following problem. One is developing software which
91    uses a very small microprocessor and a very limited C compiler. The chip
92    is so small, you can't print anything from the code, log, debug or
93    anything else. One debugs this code by using the "burn" and "crash" method
94    - you burn the chip (download the code), run the code, observe the
95    results, make changes and try again. This is a crude method which is
96    usually the one used. But it can be quite time consuming.</p>
97<p>Consider an alternative. Build and compile your code in testable
98    modules. For each module write a test which exercises all the code and
99    makes it work. Finally download your code into the chip and - voil&#224; -
100    working product. This sounds great, but there's one problem. Our target
101    processor - in this case a PIC162550 from Microchip Technology is only an
102    8 bit CPU. The compiler we use defines INT as 8 bits. This (and a few
103    other problems), make our algorithm testing environment differ from our
104    target environment. We can address this by defining INT as a safe integer
105    with a range of 8 bits. By using a custom promotion policy, we can force
106    the evaluation of C++ expressions in the test environment to be the same
107    as that in the target environment. Also in our target environment, we can
108    trap any overflows or other errors. So we can write and test our code on
109    our desktop system and download the code to the target knowing that it
110    just has to work. This is a huge time saver and confidence builder. For an
111    extended example on how this is done, look at <a class="link" href="safety_critical_embedded_controller.html" title="Safety Critical Embedded Controller">Safety
112    Critical Embedded Controller</a> .</p>
113</div>
114<div class="section">
115<div class="titlepage"><div><div><h5 class="title">
116<a name="idm130202633184"></a>Header</h5></div></div></div>
117<p><code class="computeroutput"><a href="../../include/cpp.hpp" target="_top"><code class="computeroutput">#include
118    &lt;boost/numeric/safe_numerics/cpp.hpp&gt; </code></a></code></p>
119</div>
120</div>
121<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
122<td align="left"></td>
123<td align="right"><div class="copyright-footer">Copyright &#169; 2012-2018 Robert Ramey<p><a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">Subject to Boost
124      Software License</a></p>
125</div></td>
126</tr></table>
127<hr>
128<div class="spirit-nav">
129<a accesskey="p" href="automatic.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../promotion_policies.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="../exception_safety.html"><img src="../images/next.png" alt="Next"></a>
130</div>
131</body>
132</html>
133