summaryrefslogtreecommitdiff
path: root/doc/html/boost_typeindex/mixing_sources_with_rtti_on_and_.html
blob: 40b54b8007c6ae3d329f5a5fb99f79e8f4817732 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Mixing sources with RTTI on and RTTI off</title>
<link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
<link rel="up" href="../boost_typeindex.html" title="Chapter&#160;37.&#160;Boost.TypeIndex 4.0">
<link rel="prev" href="rtti_emulation_limitations.html" title="RTTI emulation limitations">
<link rel="next" href="acknowledgements.html" title="Acknowledgements">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
<td align="center"><a href="../../../index.html">Home</a></td>
<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="rtti_emulation_limitations.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../boost_typeindex.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="acknowledgements.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="boost_typeindex.mixing_sources_with_rtti_on_and_"></a><a class="link" href="mixing_sources_with_rtti_on_and_.html" title="Mixing sources with RTTI on and RTTI off">Mixing
    sources with RTTI on and RTTI off</a>
</h2></div></div></div>
<p>
      Linking a binary from source files that were compiled with different RTTI flags
      is not a very good idea and may lead to a lot of surprises. However if there
      is a very strong need, TypeIndex library provides a solution for mixing sources:
      just define <code class="computeroutput"><a class="link" href="../BOOST_TYPE_INDEX_FORCE_NO_RTTI_COMPATIBILITY.html" title="Macro BOOST_TYPE_INDEX_FORCE_NO_RTTI_COMPATIBILITY">BOOST_TYPE_INDEX_FORCE_NO_RTTI_COMPATIBILITY</a></code>
      macro. This would lead to usage of same type_index class (<code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">typeindex</span><span class="special">::</span><span class="identifier">ctti_type_index</span></code>
      or <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">typeindex</span><span class="special">::</span><span class="identifier">stl_type_index</span></code>) all around the project.
    </p>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>
        Do not forget to rebuild <span class="bold"><strong>all</strong></span> the projects
        with <code class="computeroutput"><span class="identifier">BOOST_TYPE_INDEX_FORCE_NO_RTTI_COMPATIBILITY</span></code>
        macro defined
      </p></td></tr>
</table></div>
<p>
      You must know that linking RTTI on and RTTI off binaries may succeed even without
      defining the <code class="computeroutput"><span class="identifier">BOOST_TYPE_INDEX_FORCE_NO_RTTI_COMPATIBILITY</span></code>
      macro, but that does not mean that you'll get a working binary. Such actions
      may break the One Definition Rule. Take a look at the table below, that shows
      how the <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">type_index</span> <span class="identifier">get_integer</span><span class="special">();</span></code> function will look like with different RTTI
      flags:
    </p>
<div class="informaltable">
<a name="boost_typeindex.mixing_sources_with_rtti_on_and_.diffs"></a><table class="table">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>
              <p>
                RTTI on
              </p>
            </th>
<th>
              <p>
                RTTI off
              </p>
            </th>
</tr></thead>
<tbody><tr>
<td>
              <p>
                <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">typeindex</span><span class="special">::</span><span class="identifier">stl_type_index</span> <span class="identifier">get_integer</span><span class="special">();</span></code>
              </p>
            </td>
<td>
              <p>
                <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">typeindex</span><span class="special">::</span><span class="identifier">ctti_type_index</span> <span class="identifier">get_integer</span><span class="special">();</span></code>
              </p>
            </td>
</tr></tbody>
</table>
</div>
<p>
      Such differences are usually not detected by linker and lead to errors at runtime.
    </p>
<div class="warning"><table border="0" summary="Warning">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="../../../doc/src/images/warning.png"></td>
<th align="left">Warning</th>
</tr>
<tr><td align="left" valign="top"><p>
        Even with <code class="computeroutput"><span class="identifier">BOOST_TYPE_INDEX_FORCE_NO_RTTI_COMPATIBILITY</span></code>
        defined there is no guarantee that everything will be OK. Libraries that
        use their own workarounds for disabled RTTI may fail to link or to work correctly.
      </p></td></tr>
</table></div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2012-2014 Antony Polukhin<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        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>)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="rtti_emulation_limitations.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../boost_typeindex.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="acknowledgements.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>