*: Regenerate.
[gcc.git] / libstdc++-v3 / doc / html / faq.html
1 <html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Frequently Asked Questions</title><meta name="generator" content="DocBook XSL-NS Stylesheets V1.76.1"><meta name="keywords" content="
2 ISO C++
3 ,
4 runtime
5 ,
6 library
7 "><link rel="home" href="index.html" title="The GNU C++ Library"><link rel="up" href="bk03.html" title=""><link rel="prev" href="bk03.html" title=""></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Frequently Asked Questions</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="bk03.html">Prev</a> </td><th width="60%" align="center"></th><td width="20%" align="right"> </td></tr></table><hr></div><div class="article" title="Frequently Asked Questions"><div class="titlepage"><div><div><h1 class="title"><a name="faq"></a>Frequently Asked Questions</h1></div><div><p class="copyright">Copyright ©
8 2008, 2010
9
10 <a class="link" href="http://www.fsf.org" target="_top">FSF</a>
11 </p></div></div><hr></div><div class="qandaset" title="Frequently Asked Questions"><a name="id570718"></a><dl><dt></dt><dd><dl><dt>1.1. <a href="faq.html#faq.what">
12 What is libstdc++?
13 </a></dt><dt>1.2. <a href="faq.html#faq.why">
14 Why should I use libstdc++?
15 </a></dt><dt>1.3. <a href="faq.html#faq.who">
16 Who's in charge of it?
17 </a></dt><dt>1.4. <a href="faq.html#faq.when">
18 When is libstdc++ going to be finished?
19 </a></dt><dt>1.5. <a href="faq.html#faq.how">
20 How do I contribute to the effort?
21 </a></dt><dt>1.6. <a href="faq.html#faq.whereis_old">
22 What happened to the older libg++? I need that!
23 </a></dt><dt>1.7. <a href="faq.html#faq.more_questions">
24 What if I have more questions?
25 </a></dt></dl></dd><dt></dt><dd><dl><dt>2.1. <a href="faq.html#faq.license.what">
26 What are the license terms for libstdc++?
27 </a></dt><dt>2.2. <a href="faq.html#faq.license.any_program">
28 So any program which uses libstdc++ falls under the GPL?
29 </a></dt><dt>2.3. <a href="faq.html#faq.license.lgpl">
30 How is that different from the GNU {Lesser,Library} GPL?
31 </a></dt><dt>2.4. <a href="faq.html#faq.license.what_restrictions">
32 I see. So, what restrictions are there on programs that use the library?
33 </a></dt></dl></dd><dt></dt><dd><dl><dt>3.1. <a href="faq.html#faq.how_to_install">How do I install libstdc++?
34 </a></dt><dt>3.2. <a href="faq.html#faq.how_to_get_sources">How does one get current libstdc++ sources?
35 </a></dt><dt>3.3. <a href="faq.html#faq.how_to_test">How do I know if it works?
36 </a></dt><dt>3.4. <a href="faq.html#faq.how_to_set_paths">How do I insure that the dynamically linked library will be found?
37 </a></dt><dt>3.5. <a href="faq.html#faq.what_is_libsupcxx">
38 What's libsupc++?
39 </a></dt><dt>3.6. <a href="faq.html#faq.size">
40 This library is HUGE!
41 </a></dt></dl></dd><dt></dt><dd><dl><dt>4.1. <a href="faq.html#faq.other_compilers">
42 Can libstdc++ be used with non-GNU compilers?
43 </a></dt><dt>4.2. <a href="faq.html#faq.solaris_long_long">
44 No 'long long' type on Solaris?
45 </a></dt><dt>4.3. <a href="faq.html#faq.predefined">
46 _XOPEN_SOURCE and _GNU_SOURCE are always defined?
47 </a></dt><dt>4.4. <a href="faq.html#faq.darwin_ctype">
48 Mac OS X ctype.h is broken! How can I fix it?
49 </a></dt><dt>4.5. <a href="faq.html#faq.threads_i386">
50 Threading is broken on i386?
51 </a></dt><dt>4.6. <a href="faq.html#faq.atomic_mips">
52 MIPS atomic operations
53 </a></dt><dt>4.7. <a href="faq.html#faq.linux_glibc">
54 Recent GNU/Linux glibc required?
55 </a></dt><dt>4.8. <a href="faq.html#faq.freebsd_wchar">
56 Can't use wchar_t/wstring on FreeBSD
57 </a></dt></dl></dd><dt></dt><dd><dl><dt>5.1. <a href="faq.html#faq.what_works">
58 What works already?
59 </a></dt><dt>5.2. <a href="faq.html#faq.standard_bugs">
60 Bugs in the ISO C++ language or library specification
61 </a></dt><dt>5.3. <a href="faq.html#faq.compiler_bugs">
62 Bugs in the compiler (gcc/g++) and not libstdc++
63 </a></dt></dl></dd><dt></dt><dd><dl><dt>6.1. <a href="faq.html#faq.stream_reopening_fails">
64 Reopening a stream fails
65 </a></dt><dt>6.2. <a href="faq.html#faq.wefcxx_verbose">
66 -Weffc++ complains too much
67 </a></dt><dt>6.3. <a href="faq.html#faq.ambiguous_overloads">
68 Ambiguous overloads after including an old-style header
69 </a></dt><dt>6.4. <a href="faq.html#faq.v2_headers">
70 The g++-3 headers are not ours
71 </a></dt><dt>6.5. <a href="faq.html#faq.boost_concept_checks">
72 Errors about *Concept and
73 constraints in the STL
74 </a></dt><dt>6.6. <a href="faq.html#faq.dlopen_crash">
75 Program crashes when using library code in a
76 dynamically-loaded library
77 </a></dt><dt>6.7. <a href="faq.html#faq.memory_leaks">
78 “Memory leaks” in containers
79 </a></dt><dt>6.8. <a href="faq.html#faq.list_size_on">
80 list::size() is O(n)!
81 </a></dt><dt>6.9. <a href="faq.html#faq.easy_to_fix">
82 Aw, that's easy to fix!
83 </a></dt></dl></dd><dt></dt><dd><dl><dt>7.1. <a href="faq.html#faq.iterator_as_pod">
84 string::iterator is not char*; vector&lt;T&gt;::iterator is not T*
85 </a></dt><dt>7.2. <a href="faq.html#faq.what_is_next">
86 What's next after libstdc++?
87 </a></dt><dt>7.3. <a href="faq.html#faq.sgi_stl">
88 What about the STL from SGI?
89 </a></dt><dt>7.4. <a href="faq.html#faq.extensions_and_backwards_compat">
90 Extensions and Backward Compatibility
91 </a></dt><dt>7.5. <a href="faq.html#faq.tr1_support">
92 Does libstdc++ support TR1?
93 </a></dt><dt>7.6. <a href="faq.html#faq.get_iso_cxx">How do I get a copy of the ISO C++ Standard?
94 </a></dt><dt>7.7. <a href="faq.html#faq.what_is_abi">
95 What's an ABI and why is it so messy?
96 </a></dt><dt>7.8. <a href="faq.html#faq.size_equals_capacity">
97 How do I make std::vector&lt;T&gt;::capacity() == std::vector&lt;T&gt;::size?
98 </a></dt></dl></dd></dl><table border="0" width="100%" summary="Q and A Set"><col align="left" width="1%"><col><tbody><tr class="toc"><td align="left" valign="top" colspan="2"><dl><dt>1.1. <a href="faq.html#faq.what">
99 What is libstdc++?
100 </a></dt><dt>1.2. <a href="faq.html#faq.why">
101 Why should I use libstdc++?
102 </a></dt><dt>1.3. <a href="faq.html#faq.who">
103 Who's in charge of it?
104 </a></dt><dt>1.4. <a href="faq.html#faq.when">
105 When is libstdc++ going to be finished?
106 </a></dt><dt>1.5. <a href="faq.html#faq.how">
107 How do I contribute to the effort?
108 </a></dt><dt>1.6. <a href="faq.html#faq.whereis_old">
109 What happened to the older libg++? I need that!
110 </a></dt><dt>1.7. <a href="faq.html#faq.more_questions">
111 What if I have more questions?
112 </a></dt></dl></td></tr><tr class="question" title="1.1."><td align="left" valign="top"><a name="faq.what"></a><a name="faq.what.q"></a><p><b>1.1.</b></p></td><td align="left" valign="top"><p>
113 What is libstdc++?
114 </p></td></tr><tr class="answer"><td align="left" valign="top"><a name="faq.what.a"></a></td><td align="left" valign="top"><p>
115 The GNU Standard C++ Library v3 is an ongoing project to
116 implement the ISO 14882 Standard C++ library as described in
117 chapters 17 through 27 and annex D. For those who want to see
118 exactly how far the project has come, or just want the latest
119 bleeding-edge code, the up-to-date source is available over
120 anonymous SVN, and can even be browsed over
121 the <a class="link" href="http://gcc.gnu.org/svn.html" target="_top">web</a>.
122 </p></td></tr><tr class="question" title="1.2."><td align="left" valign="top"><a name="faq.why"></a><a name="q-why"></a><p><b>1.2.</b></p></td><td align="left" valign="top"><p>
123 Why should I use libstdc++?
124 </p></td></tr><tr class="answer"><td align="left" valign="top"><a name="a-why"></a></td><td align="left" valign="top"><p>
125 The completion of the ISO C++ standardization gave the C++
126 community a powerful set of reuseable tools in the form of the C++
127 Standard Library. However, all existing C++ implementations are
128 (as the Draft Standard used to say) <span class="quote"><span class="quote">incomplet and
129 incorrekt</span></span>, and many suffer from limitations of the compilers
130 that use them.
131 </p><p>
132 The GNU compiler collection
133 (<span class="command"><strong>gcc</strong></span>, <span class="command"><strong>g++</strong></span>, etc) is widely
134 considered to be one of the leading compilers in the world. Its
135 development is overseen by the
136 <a class="link" href="http://gcc.gnu.org/" target="_top">GCC team</a>. All of
137 the rapid development and near-legendary
138 <a class="link" href="http://gcc.gnu.org/buildstat.html" target="_top">portability</a>
139 that are the hallmarks of an open-source project are being
140 applied to libstdc++.
141 </p><p>
142 That means that all of the Standard classes and functions will be
143 freely available and fully compliant. (Such as
144 <code class="classname">string</code>,
145 <code class="classname">vector&lt;&gt;</code>, iostreams, and algorithms.)
146 Programmers will no longer need to <span class="quote"><span class="quote">roll their own</span></span>
147 nor be worried about platform-specific incompatibilities.
148 </p></td></tr><tr class="question" title="1.3."><td align="left" valign="top"><a name="faq.who"></a><a name="q-who"></a><p><b>1.3.</b></p></td><td align="left" valign="top"><p>
149 Who's in charge of it?
150 </p></td></tr><tr class="answer"><td align="left" valign="top"><a name="a-who"></a></td><td align="left" valign="top"><p>
151 The libstdc++ project is contributed to by several developers
152 all over the world, in the same way as GCC or the Linux kernel.
153 Benjamin Kosnik, Gabriel Dos Reis, Phil Edwards, Ulrich Drepper,
154 Loren James Rittle, and Paolo Carlini are the lead maintainers of
155 the SVN archive.
156 </p><p>
157 Development and discussion is held on the libstdc++ mailing
158 list. Subscribing to the list, or searching the list
159 archives, is open to everyone. You can read instructions for
160 doing so on the <a class="link" href="http://gcc.gnu.org/libstdc++/" target="_top">homepage</a>.
161 If you have questions, ideas, code, or are just curious, sign up!
162 </p></td></tr><tr class="question" title="1.4."><td align="left" valign="top"><a name="faq.when"></a><a name="q-when"></a><p><b>1.4.</b></p></td><td align="left" valign="top"><p>
163 When is libstdc++ going to be finished?
164 </p></td></tr><tr class="answer"><td align="left" valign="top"><a name="a-when"></a></td><td align="left" valign="top"><p>
165 Nathan Myers gave the best of all possible answers, responding to
166 a Usenet article asking this question: <span class="emphasis"><em>Sooner, if you
167 help.</em></span>
168 </p></td></tr><tr class="question" title="1.5."><td align="left" valign="top"><a name="faq.how"></a><a name="q-how"></a><p><b>1.5.</b></p></td><td align="left" valign="top"><p>
169 How do I contribute to the effort?
170 </p></td></tr><tr class="answer"><td align="left" valign="top"><a name="a-how"></a></td><td align="left" valign="top"><p>
171 Here is <a class="link" href="manual/appendix_contributing.html" title="Appendix A.  Contributing">a page devoted to
172 this topic</a>. Subscribing to the mailing list (see above, or
173 the homepage) is a very good idea if you have something to
174 contribute, or if you have spare time and want to
175 help. Contributions don't have to be in the form of source code;
176 anybody who is willing to help write documentation, for example,
177 or has found a bug in code that we all thought was working and is
178 willing to provide details, is more than welcome!
179 </p></td></tr><tr class="question" title="1.6."><td align="left" valign="top"><a name="faq.whereis_old"></a><a name="q-whereis_old"></a><p><b>1.6.</b></p></td><td align="left" valign="top"><p>
180 What happened to the older libg++? I need that!
181 </p></td></tr><tr class="answer"><td align="left" valign="top"><a name="a-whereis_old"></a></td><td align="left" valign="top"><p>
182 The most recent libg++ README states that libg++ is no longer
183 being actively maintained. It should not be used for new
184 projects, and is only being kicked along to support older code.
185 </p><p>
186 More information in the <a class="link" href="manual/backwards.html" title="Backwards Compatibility">backwards compatibility documentation</a>
187 </p></td></tr><tr class="question" title="1.7."><td align="left" valign="top"><a name="faq.more_questions"></a><a name="q-more_questions"></a><p><b>1.7.</b></p></td><td align="left" valign="top"><p>
188 What if I have more questions?
189 </p></td></tr><tr class="answer"><td align="left" valign="top"><a name="a-more_questions"></a></td><td align="left" valign="top"><p>
190 If you have read the README file, and your question remains
191 unanswered, then just ask the mailing list. At present, you do not
192 need to be subscribed to the list to send a message to it. More
193 information is available on the homepage (including how to browse
194 the list archives); to send a message to the list,
195 use <code class="email">&lt;<a class="email" href="mailto:libstdc++@gcc.gnu.org">libstdc++@gcc.gnu.org</a>&gt;</code>.
196 </p><p>
197 If you have a question that you think should be included
198 here, or if you have a question <span class="emphasis"><em>about</em></span> a question/answer
199 here, please send email to the libstdc++ mailing list, as above.
200 </p></td></tr><tr class="toc"><td align="left" valign="top" colspan="2"><dl><dt>2.1. <a href="faq.html#faq.license.what">
201 What are the license terms for libstdc++?
202 </a></dt><dt>2.2. <a href="faq.html#faq.license.any_program">
203 So any program which uses libstdc++ falls under the GPL?
204 </a></dt><dt>2.3. <a href="faq.html#faq.license.lgpl">
205 How is that different from the GNU {Lesser,Library} GPL?
206 </a></dt><dt>2.4. <a href="faq.html#faq.license.what_restrictions">
207 I see. So, what restrictions are there on programs that use the library?
208 </a></dt></dl></td></tr><tr class="question" title="2.1."><td align="left" valign="top"><a name="faq.license.what"></a><a name="q-license.what"></a><p><b>2.1.</b></p></td><td align="left" valign="top"><p>
209 What are the license terms for libstdc++?
210 </p></td></tr><tr class="answer"><td align="left" valign="top"><a name="a-license.what"></a></td><td align="left" valign="top"><p>
211 See <a class="link" href="manual/license.html" title="License">our license description</a>
212 for these and related questions.
213 </p></td></tr><tr class="question" title="2.2."><td align="left" valign="top"><a name="faq.license.any_program"></a><a name="q-license.any_program"></a><p><b>2.2.</b></p></td><td align="left" valign="top"><p>
214 So any program which uses libstdc++ falls under the GPL?
215 </p></td></tr><tr class="answer"><td align="left" valign="top"><a name="a-license.any_program"></a></td><td align="left" valign="top"><p>
216 No. The special exception permits use of the library in
217 proprietary applications.
218 </p></td></tr><tr class="question" title="2.3."><td align="left" valign="top"><a name="faq.license.lgpl"></a><a name="q-license.lgpl"></a><p><b>2.3.</b></p></td><td align="left" valign="top"><p>
219 How is that different from the GNU {Lesser,Library} GPL?
220 </p></td></tr><tr class="answer"><td align="left" valign="top"><a name="a-license.lgpl"></a></td><td align="left" valign="top"><p>
221 The LGPL requires that users be able to replace the LGPL code with a
222 modified version; this is trivial if the library in question is a C
223 shared library. But there's no way to make that work with C++, where
224 much of the library consists of inline functions and templates, which
225 are expanded inside the code that uses the library. So to allow people
226 to replace the library code, someone using the library would have to
227 distribute their own source, rendering the LGPL equivalent to the GPL.
228 </p></td></tr><tr class="question" title="2.4."><td align="left" valign="top"><a name="faq.license.what_restrictions"></a><a name="q-license.what_restrictions"></a><p><b>2.4.</b></p></td><td align="left" valign="top"><p>
229 I see. So, what restrictions are there on programs that use the library?
230 </p></td></tr><tr class="answer"><td align="left" valign="top"><a name="a-license.what_restrictions"></a></td><td align="left" valign="top"><p>
231 None. We encourage such programs to be released as open source,
232 but we won't punish you or sue you if you choose otherwise.
233 </p></td></tr><tr class="toc"><td align="left" valign="top" colspan="2"><dl><dt>3.1. <a href="faq.html#faq.how_to_install">How do I install libstdc++?
234 </a></dt><dt>3.2. <a href="faq.html#faq.how_to_get_sources">How does one get current libstdc++ sources?
235 </a></dt><dt>3.3. <a href="faq.html#faq.how_to_test">How do I know if it works?
236 </a></dt><dt>3.4. <a href="faq.html#faq.how_to_set_paths">How do I insure that the dynamically linked library will be found?
237 </a></dt><dt>3.5. <a href="faq.html#faq.what_is_libsupcxx">
238 What's libsupc++?
239 </a></dt><dt>3.6. <a href="faq.html#faq.size">
240 This library is HUGE!
241 </a></dt></dl></td></tr><tr class="question" title="3.1."><td align="left" valign="top"><a name="faq.how_to_install"></a><a name="q-how_to_install"></a><p><b>3.1.</b></p></td><td align="left" valign="top"><p>How do I install libstdc++?
242 </p></td></tr><tr class="answer"><td align="left" valign="top"><a name="a-how_to_install"></a></td><td align="left" valign="top"><p>
243 Often libstdc++ comes pre-installed as an integral part of many
244 existing GNU/Linux and Unix systems, as well as many embedded
245 development tools. It may be necessary to install extra
246 development packages to get the headers, or the documentation, or
247 the source: please consult your vendor for details.
248 </p><p>
249 To build and install from the GNU GCC sources, please consult the
250 <a class="link" href="manual/setup.html" title="Chapter 2. Setup">setup
251 documentation</a> for detailed
252 instructions. You may wish to browse those files ahead
253 of time to get a feel for what's required.
254 </p></td></tr><tr class="question" title="3.2."><td align="left" valign="top"><a name="faq.how_to_get_sources"></a><a name="q-how_to_get_sources"></a><p><b>3.2.</b></p></td><td align="left" valign="top"><p>How does one get current libstdc++ sources?
255 </p></td></tr><tr class="answer"><td align="left" valign="top"><a name="a-how_to_get_sources"></a></td><td align="left" valign="top"><p>
256 Libstdc++ sources for all official releases can be obtained as
257 part of the GCC sources, available from various sites and
258 mirrors. A full <a class="link" href="http://gcc.gnu.org/mirrors.html" target="_top">list of
259 download sites</a> is provided on the main GCC site.
260 </p><p>
261 Current libstdc++ sources can always be checked out of the main
262 GCC source repository using the appropriate version control
263 tool. At this time, that tool
264 is <span class="application">Subversion</span>.
265 </p><p>
266 <span class="application">Subversion</span>, or <acronym class="acronym">SVN</acronym>, is
267 one of several revision control packages. It was selected for GNU
268 projects because it's free (speech), free (beer), and very high
269 quality. The <a class="link" href="http://subversion.tigris.org" target="_top"> Subversion
270 home page</a> has a better description.
271 </p><p>
272 The <span class="quote"><span class="quote">anonymous client checkout</span></span> feature of SVN is
273 similar to anonymous FTP in that it allows anyone to retrieve
274 the latest libstdc++ sources.
275 </p><p>
276 For more information
277 see <a class="link" href="http://gcc.gnu.org/svn.html" target="_top"><acronym class="acronym">SVN</acronym>
278 details</a>.
279 </p></td></tr><tr class="question" title="3.3."><td align="left" valign="top"><a name="faq.how_to_test"></a><a name="q-how_to_test"></a><p><b>3.3.</b></p></td><td align="left" valign="top"><p>How do I know if it works?
280 </p></td></tr><tr class="answer"><td align="left" valign="top"><a name="a-how_to_test"></a></td><td align="left" valign="top"><p>
281 Libstdc++ comes with its own validation testsuite, which includes
282 conformance testing, regression testing, ABI testing, and
283 performance testing. Please consult the
284 <a class="link" href="http://gcc.gnu.org/install/test.html" target="_top">testing
285 documentation</a> for more details.
286 </p><p>
287 If you find bugs in the testsuite programs themselves, or if you
288 think of a new test program that should be added to the suite,
289 <span class="emphasis"><em>please</em></span> write up your idea and send it to the list!
290 </p></td></tr><tr class="question" title="3.4."><td align="left" valign="top"><a name="faq.how_to_set_paths"></a><a name="q-how_to_set_paths"></a><p><b>3.4.</b></p></td><td align="left" valign="top"><p>How do I insure that the dynamically linked library will be found?
291 </p></td></tr><tr class="answer"><td align="left" valign="top"><a name="a-how_to_set_paths"></a></td><td align="left" valign="top"><p>
292 Depending on your platform and library version, the error message might
293 be similar to one of the following:
294 </p><pre class="screen">
295 ./a.out: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory
296
297 /usr/libexec/ld-elf.so.1: Shared object "libstdc++.so.6" not found
298 </pre><p>
299 This doesn't mean that the shared library isn't installed, only
300 that the dynamic linker can't find it. When a dynamically-linked
301 executable is run the linker finds and loads the required shared
302 libraries by searching a pre-configured list of directories. If
303 the directory where you've installed libstdc++ is not in this list
304 then the libraries won't be found. The simplest way to fix this is
305 to use the <code class="literal">LD_LIBRARY_PATH</code> environment variable,
306 which is a colon-separated list of directories in which the linker
307 will search for shared libraries:
308 </p><pre class="screen">
309 LD_LIBRARY_PATH=${prefix}/lib:$LD_LIBRARY_PATH
310 export LD_LIBRARY_PATH
311 </pre><p>
312 The exact environment variable to use will depend on your
313 platform, e.g. DYLD_LIBRARY_PATH for Darwin,
314 LD_LIBRARY_PATH_32/LD_LIBRARY_PATH_64 for Solaris 32-/64-bit
315 and SHLIB_PATH for HP-UX.
316 </p><p>
317 See the man pages for <span class="command"><strong>ld</strong></span>, <span class="command"><strong>ldd</strong></span>
318 and <span class="command"><strong>ldconfig</strong></span> for more information. The dynamic
319 linker has different names on different platforms but the man page
320 is usually called something such as <code class="filename">ld.so/rtld/dld.so</code>.
321 </p><p>
322 Using LD_LIBRARY_PATH is not always the best solution, <a class="link" href="manual/using_dynamic_or_shared.html#manual.intro.using.linkage.dynamic" title="Finding Dynamic or Shared Libraries">Finding Dynamic or Shared
323 Libraries</a> in the manual gives some alternatives.
324 </p></td></tr><tr class="question" title="3.5."><td align="left" valign="top"><a name="faq.what_is_libsupcxx"></a><a name="q-what_is_libsupcxx"></a><p><b>3.5.</b></p></td><td align="left" valign="top"><p>
325 What's libsupc++?
326 </p></td></tr><tr class="answer"><td align="left" valign="top"><a name="a-what_is_libsupcxx"></a></td><td align="left" valign="top"><p>
327 If the only functions from <code class="filename">libstdc++.a</code>
328 which you need are language support functions (those listed in
329 <a class="link" href="manual/support.html" title="Chapter 4.  Support">clause 18</a> of the
330 standard, e.g., <code class="function">new</code> and
331 <code class="function">delete</code>), then try linking against
332 <code class="filename">libsupc++.a</code>, which is a subset of
333 <code class="filename">libstdc++.a</code>. (Using <span class="command"><strong>gcc</strong></span>
334 instead of <span class="command"><strong>g++</strong></span> and explicitly linking in
335 <code class="filename">libsupc++.a</code> via <code class="literal">-lsupc++</code>
336 for the final link step will do it). This library contains only
337 those support routines, one per object file. But if you are
338 using anything from the rest of the library, such as IOStreams
339 or vectors, then you'll still need pieces from
340 <code class="filename">libstdc++.a</code>.
341 </p></td></tr><tr class="question" title="3.6."><td align="left" valign="top"><a name="faq.size"></a><a name="q-size"></a><p><b>3.6.</b></p></td><td align="left" valign="top"><p>
342 This library is HUGE!
343 </p></td></tr><tr class="answer"><td align="left" valign="top"><a name="a-size"></a></td><td align="left" valign="top"><p>
344 Usually the size of libraries on disk isn't noticeable. When a
345 link editor (or simply <span class="quote"><span class="quote">linker</span></span>) pulls things from a
346 static archive library, only the necessary object files are copied
347 into your executable, not the entire library. Unfortunately, even
348 if you only need a single function or variable from an object file,
349 the entire object file is extracted. (There's nothing unique to C++
350 or libstdc++ about this; it's just common behavior, given here
351 for background reasons.)
352 </p><p>
353 Some of the object files which make up libstdc++.a are rather large.
354 If you create a statically-linked executable with
355 <code class="literal">-static</code>, those large object files are suddenly part
356 of your executable. Historically the best way around this was to
357 only place a very few functions (often only a single one) in each
358 source/object file; then extracting a single function is the same
359 as extracting a single .o file. For libstdc++ this is only
360 possible to a certain extent; the object files in question contain
361 template classes and template functions, pre-instantiated, and
362 splitting those up causes severe maintenance headaches.
363 </p><p>
364 On supported platforms, libstdc++ takes advantage of garbage
365 collection in the GNU linker to get a result similar to separating
366 each symbol into a separate source and object files. On these platforms,
367 GNU ld can place each function and variable into its own
368 section in a .o file. The GNU linker can then perform garbage
369 collection on unused sections; this reduces the situation to only
370 copying needed functions into the executable, as before, but all
371 happens automatically.
372 </p></td></tr><tr class="toc"><td align="left" valign="top" colspan="2"><dl><dt>4.1. <a href="faq.html#faq.other_compilers">
373 Can libstdc++ be used with non-GNU compilers?
374 </a></dt><dt>4.2. <a href="faq.html#faq.solaris_long_long">
375 No 'long long' type on Solaris?
376 </a></dt><dt>4.3. <a href="faq.html#faq.predefined">
377 _XOPEN_SOURCE and _GNU_SOURCE are always defined?
378 </a></dt><dt>4.4. <a href="faq.html#faq.darwin_ctype">
379 Mac OS X ctype.h is broken! How can I fix it?
380 </a></dt><dt>4.5. <a href="faq.html#faq.threads_i386">
381 Threading is broken on i386?
382 </a></dt><dt>4.6. <a href="faq.html#faq.atomic_mips">
383 MIPS atomic operations
384 </a></dt><dt>4.7. <a href="faq.html#faq.linux_glibc">
385 Recent GNU/Linux glibc required?
386 </a></dt><dt>4.8. <a href="faq.html#faq.freebsd_wchar">
387 Can't use wchar_t/wstring on FreeBSD
388 </a></dt></dl></td></tr><tr class="question" title="4.1."><td align="left" valign="top"><a name="faq.other_compilers"></a><a name="q-other_compilers"></a><p><b>4.1.</b></p></td><td align="left" valign="top"><p>
389 Can libstdc++ be used with non-GNU compilers?
390 </p></td></tr><tr class="answer"><td align="left" valign="top"><a name="a-other_compilers"></a></td><td align="left" valign="top"><p>
391 Perhaps.
392 </p><p>
393 Since the goal of ISO Standardization is for all C++
394 implementations to be able to share code, libstdc++ should be
395 usable under any ISO-compliant compiler, at least in theory.
396 </p><p>
397 However, the reality is that libstdc++ is targeted and optimized
398 for GCC/g++. This means that often libstdc++ uses specific,
399 non-standard features of g++ that are not present in older
400 versions of proprietary compilers. It may take as much as a year or two
401 after an official release of GCC that contains these features for
402 proprietary tools to support these constructs.
403 </p><p>
404 In the near past, specific released versions of libstdc++ have
405 been known to work with versions of the EDG C++ compiler, and
406 vendor-specific proprietary C++ compilers such as the Intel ICC
407 C++ compiler.
408 </p></td></tr><tr class="question" title="4.2."><td align="left" valign="top"><a name="faq.solaris_long_long"></a><a name="q-solaris_long_long"></a><p><b>4.2.</b></p></td><td align="left" valign="top"><p>
409 No 'long long' type on Solaris?
410 </p></td></tr><tr class="answer"><td align="left" valign="top"><a name="a-solaris_long_long"></a></td><td align="left" valign="top"><p>
411 By default we try to support the C99 <span class="type">long long</span> type.
412 This requires that certain functions from your C library be present.
413 </p><p>
414 Up through release 3.0.2 the platform-specific tests performed by
415 libstdc++ were too general, resulting in a conservative approach
416 to enabling the <span class="type">long long</span> code paths. The most
417 commonly reported platform affected was Solaris.
418 </p><p>
419 This has been fixed for libstdc++ releases greater than 3.0.3.
420 </p></td></tr><tr class="question" title="4.3."><td align="left" valign="top"><a name="faq.predefined"></a><a name="q-predefined"></a><p><b>4.3.</b></p></td><td align="left" valign="top"><p>
421 <code class="constant">_XOPEN_SOURCE</code> and <code class="constant">_GNU_SOURCE</code> are always defined?
422 </p></td></tr><tr class="answer"><td align="left" valign="top"><a name="a-predefined"></a></td><td align="left" valign="top"><p>On Solaris, g++ (but not gcc) always defines the preprocessor
423 macro <code class="constant">_XOPEN_SOURCE</code>. On GNU/Linux, the same happens
424 with <code class="constant">_GNU_SOURCE</code>. (This is not an exhaustive list;
425 other macros and other platforms are also affected.)
426 </p><p>These macros are typically used in C library headers, guarding new
427 versions of functions from their older versions. The C++ standard
428 library includes the C standard library, but it requires the C90
429 version, which for backwards-compatibility reasons is often not the
430 default for many vendors.
431 </p><p>More to the point, the C++ standard requires behavior which is only
432 available on certain platforms after certain symbols are defined.
433 Usually the issue involves I/O-related typedefs. In order to
434 ensure correctness, the compiler simply predefines those symbols.
435 </p><p>Note that it's not enough to #define them only when the library is
436 being built (during installation). Since we don't have an 'export'
437 keyword, much of the library exists as headers, which means that
438 the symbols must also be defined as your programs are parsed and
439 compiled.
440 </p><p>To see which symbols are defined, look for CPLUSPLUS_CPP_SPEC in
441 the gcc config headers for your target (and try changing them to
442 see what happens when building complicated code). You can also run
443 <span class="command"><strong>g++ -E -dM - &lt; /dev/null"</strong></span> to display
444 a list of predefined macros for any particular installation.
445 </p><p>This has been discussed on the mailing lists
446 <a class="link" href="http://gcc.gnu.org/cgi-bin/htsearch?method=and&amp;format=builtin-long&amp;sort=score&amp;words=_XOPEN_SOURCE+Solaris" target="_top">quite a bit</a>.
447 </p><p>This method is something of a wart. We'd like to find a cleaner
448 solution, but nobody yet has contributed the time.
449 </p></td></tr><tr class="question" title="4.4."><td align="left" valign="top"><a name="faq.darwin_ctype"></a><a name="q-darwin_ctype"></a><p><b>4.4.</b></p></td><td align="left" valign="top"><p>
450 Mac OS X <code class="filename">ctype.h</code> is broken! How can I fix it?
451 </p></td></tr><tr class="answer"><td align="left" valign="top"><a name="a-darwin_ctype"></a></td><td align="left" valign="top"><p>This is a long-standing bug in the OS X support. Fortunately,
452 the patch is quite simple, and well-known.
453 <a class="link" href="http://gcc.gnu.org/ml/gcc/2002-03/msg00817.html" target="_top"> Here's a
454 link to the solution</a>.
455 </p></td></tr><tr class="question" title="4.5."><td align="left" valign="top"><a name="faq.threads_i386"></a><a name="q-threads_i386"></a><p><b>4.5.</b></p></td><td align="left" valign="top"><p>
456 Threading is broken on i386?
457 </p></td></tr><tr class="answer"><td align="left" valign="top"><a name="a-threads_i386"></a></td><td align="left" valign="top"><p>
458 </p><p>Support for atomic integer operations is/was broken on i386
459 platforms. The assembly code accidentally used opcodes that are
460 only available on the i486 and later. So if you configured GCC
461 to target, for example, i386-linux, but actually used the programs
462 on an i686, then you would encounter no problems. Only when
463 actually running the code on a i386 will the problem appear.
464 </p><p>This is fixed in 3.2.2.
465 </p></td></tr><tr class="question" title="4.6."><td align="left" valign="top"><a name="faq.atomic_mips"></a><a name="q-atomic_mips"></a><p><b>4.6.</b></p></td><td align="left" valign="top"><p>
466 MIPS atomic operations
467 </p></td></tr><tr class="answer"><td align="left" valign="top"><a name="a-atomic_mips"></a></td><td align="left" valign="top"><p>
468 The atomic locking routines for MIPS targets requires MIPS II
469 and later. A patch went in just after the 3.3 release to
470 make mips* use the generic implementation instead. You can also
471 configure for mipsel-elf as a workaround.
472 </p><p>
473 The mips*-*-linux* port continues to use the MIPS II routines, and more
474 work in this area is expected.
475 </p></td></tr><tr class="question" title="4.7."><td align="left" valign="top"><a name="faq.linux_glibc"></a><a name="q-linux_glibc"></a><p><b>4.7.</b></p></td><td align="left" valign="top"><p>
476 Recent GNU/Linux glibc required?
477 </p></td></tr><tr class="answer"><td align="left" valign="top"><a name="a-linux_glibc"></a></td><td align="left" valign="top"><p>When running on GNU/Linux, libstdc++ 3.2.1 (shared library version
478 5.0.1) and later uses localization and formatting code from the system
479 C library (glibc) version 2.2.5 which contains necessary bugfixes.
480 Most GNU/Linux distros make more recent versions available now.
481 libstdc++ 4.6.0 and later require glibc 2.3 or later for this
482 localization and formatting code.
483 </p><p>The guideline is simple: the more recent the C++ library, the
484 more recent the C library. (This is also documented in the main
485 GCC installation instructions.)
486 </p></td></tr><tr class="question" title="4.8."><td align="left" valign="top"><a name="faq.freebsd_wchar"></a><a name="q-freebsd_wchar"></a><p><b>4.8.</b></p></td><td align="left" valign="top"><p>
487 Can't use wchar_t/wstring on FreeBSD
488 </p></td></tr><tr class="answer"><td align="left" valign="top"><a name="a-freebsd_wchar"></a></td><td align="left" valign="top"><p>
489 Older versions of FreeBSD's C library do not have sufficient
490 support for wide character functions, and as a result the
491 libstdc++ configury decides that wchar_t support should be
492 disabled. In addition, the libstdc++ platform checks that
493 enabled <span class="type">wchar_t</span> were quite strict, and not granular
494 enough to detect when the minimal support to
495 enable <span class="type">wchar_t</span> and C++ library structures
496 like <code class="classname">wstring</code> were present. This impacted Solaris,
497 Darwin, and BSD variants, and is fixed in libstdc++ versions post 4.1.0.
498 </p><p>
499 </p></td></tr><tr class="toc"><td align="left" valign="top" colspan="2"><dl><dt>5.1. <a href="faq.html#faq.what_works">
500 What works already?
501 </a></dt><dt>5.2. <a href="faq.html#faq.standard_bugs">
502 Bugs in the ISO C++ language or library specification
503 </a></dt><dt>5.3. <a href="faq.html#faq.compiler_bugs">
504 Bugs in the compiler (gcc/g++) and not libstdc++
505 </a></dt></dl></td></tr><tr class="question" title="5.1."><td align="left" valign="top"><a name="faq.what_works"></a><a name="q-what_works"></a><p><b>5.1.</b></p></td><td align="left" valign="top"><p>
506 What works already?
507 </p></td></tr><tr class="answer"><td align="left" valign="top"><a name="a-what_works"></a></td><td align="left" valign="top"><p>
508 Short answer: Pretty much everything <span class="emphasis"><em>works</em></span>
509 except for some corner cases. Support for localization
510 in <code class="classname">locale</code> may be incomplete on non-GNU
511 platforms. Also dependant on the underlying platform is support
512 for <span class="type">wchar_t</span> and <span class="type">long
513 long</span> specializations, and details of thread support.
514 </p><p>
515 Long answer: See the implementation status pages for
516 <a class="link" href="manual/status.html#status.iso.1998" title="C++ 1998/2003">C++98</a>,
517 <a class="link" href="manual/status.html#status.iso.tr1" title="C++ TR1">TR1</a>, and
518 <a class="link" href="manual/status.html#status.iso.2011" title="C++ 2011">C++11</a>.
519 </p></td></tr><tr class="question" title="5.2."><td align="left" valign="top"><a name="faq.standard_bugs"></a><a name="q-standard_bugs"></a><p><b>5.2.</b></p></td><td align="left" valign="top"><p>
520 Bugs in the ISO C++ language or library specification
521 </p></td></tr><tr class="answer"><td align="left" valign="top"><a name="a-standard_bugs"></a></td><td align="left" valign="top"><p>
522 Unfortunately, there are some.
523 </p><p>
524 For those people who are not part of the ISO Library Group
525 (i.e., nearly all of us needing to read this page in the first
526 place), a public list of the library defects is occasionally
527 published on <a class="link" href="http://www.open-std.org/jtc1/sc22/wg21/" target="_top">the WG21
528 website</a>.
529 Some of these issues have resulted in code changes in libstdc++.
530 </p><p>
531 If you think you've discovered a new bug that is not listed,
532 please post a message describing your problem to the author of
533 the library issues list or the Usenet group comp.lang.c++.moderated.
534 </p></td></tr><tr class="question" title="5.3."><td align="left" valign="top"><a name="faq.compiler_bugs"></a><a name="q-compiler_bugs"></a><p><b>5.3.</b></p></td><td align="left" valign="top"><p>
535 Bugs in the compiler (gcc/g++) and not libstdc++
536 </p></td></tr><tr class="answer"><td align="left" valign="top"><a name="a-compiler_bugs"></a></td><td align="left" valign="top"><p>
537 On occasion, the compiler is wrong. Please be advised that this
538 happens much less often than one would think, and avoid jumping to
539 conclusions.
540 </p><p>
541 First, examine the ISO C++ standard. Second, try another compiler
542 or an older version of the GNU compilers. Third, you can find more
543 information on the libstdc++ and the GCC mailing lists: search
544 these lists with terms describing your issue.
545 </p><p>
546 Before reporting a bug, please examine the
547 <a class="link" href="http://gcc.gnu.org/bugs/" target="_top">bugs database</a> with the
548 category set to <span class="quote">“<span class="quote">g++</span>”</span>.
549 </p></td></tr><tr class="toc"><td align="left" valign="top" colspan="2"><dl><dt>6.1. <a href="faq.html#faq.stream_reopening_fails">
550 Reopening a stream fails
551 </a></dt><dt>6.2. <a href="faq.html#faq.wefcxx_verbose">
552 -Weffc++ complains too much
553 </a></dt><dt>6.3. <a href="faq.html#faq.ambiguous_overloads">
554 Ambiguous overloads after including an old-style header
555 </a></dt><dt>6.4. <a href="faq.html#faq.v2_headers">
556 The g++-3 headers are not ours
557 </a></dt><dt>6.5. <a href="faq.html#faq.boost_concept_checks">
558 Errors about *Concept and
559 constraints in the STL
560 </a></dt><dt>6.6. <a href="faq.html#faq.dlopen_crash">
561 Program crashes when using library code in a
562 dynamically-loaded library
563 </a></dt><dt>6.7. <a href="faq.html#faq.memory_leaks">
564 “Memory leaks” in containers
565 </a></dt><dt>6.8. <a href="faq.html#faq.list_size_on">
566 list::size() is O(n)!
567 </a></dt><dt>6.9. <a href="faq.html#faq.easy_to_fix">
568 Aw, that's easy to fix!
569 </a></dt></dl></td></tr><tr class="question" title="6.1."><td align="left" valign="top"><a name="faq.stream_reopening_fails"></a><a name="q-stream_reopening_fails"></a><p><b>6.1.</b></p></td><td align="left" valign="top"><p>
570 Reopening a stream fails
571 </p></td></tr><tr class="answer"><td align="left" valign="top"><a name="a-stream_reopening_fails"></a></td><td align="left" valign="top"><p>
572 One of the most-reported non-bug reports. Executing a sequence like:
573 </p><div class="literallayout"><p><br>
574     #include &lt;fstream&gt;<br>
575     ...<br>
576     std::fstream  fs(<span class="quote">“<span class="quote">a_file</span>”</span>);<br>
577     // .<br>
578     // . do things with fs...<br>
579     // .<br>
580     fs.close();<br>
581     fs.open(<span class="quote">“<span class="quote">a_new_file</span>”</span>);<br>
582     </p></div><p>
583 All operations on the re-opened <code class="varname">fs</code> will fail, or at
584 least act very strangely. Yes, they often will, especially if
585 <code class="varname">fs</code> reached the EOF state on the previous file. The
586 reason is that the state flags are <span class="emphasis"><em>not</em></span> cleared
587 on a successful call to open(). The standard unfortunately did
588 not specify behavior in this case, and to everybody's great sorrow,
589 the <a class="link" href="manual/bugs.html" title="Bugs">proposed LWG resolution in
590 DR #22</a> is to leave the flags unchanged. You must insert a call
591 to <code class="function">fs.clear()</code> between the calls to close() and open(),
592 and then everything will work like we all expect it to work.
593 <span class="emphasis"><em>Update:</em></span> for GCC 4.0 we implemented the resolution
594 of <a class="link" href="manual/bugs.html" title="Bugs">DR #409</a> and open()
595 now calls <code class="function">clear()</code> on success!
596 </p></td></tr><tr class="question" title="6.2."><td align="left" valign="top"><a name="faq.wefcxx_verbose"></a><a name="q-wefcxx_verbose"></a><p><b>6.2.</b></p></td><td align="left" valign="top"><p>
597 -Weffc++ complains too much
598 </p></td></tr><tr class="answer"><td align="left" valign="top"><a name="a-wefcxx_verbose"></a></td><td align="left" valign="top"><p>
599 Many warnings are emitted when <code class="literal">-Weffc++</code> is used. Making
600 libstdc++ <code class="literal">-Weffc++</code>-clean is not a goal of the project,
601 for a few reasons. Mainly, that option tries to enforce
602 object-oriented programming, while the Standard Library isn't
603 necessarily trying to be OO.
604 </p><p>
605 We do, however, try to have libstdc++ sources as clean as possible. If
606 you see some simple changes that pacify <code class="literal">-Weffc++</code>
607 without other drawbacks, send us a patch.
608 </p></td></tr><tr class="question" title="6.3."><td align="left" valign="top"><a name="faq.ambiguous_overloads"></a><a name="q-ambiguous_overloads"></a><p><b>6.3.</b></p></td><td align="left" valign="top"><p>
609 Ambiguous overloads after including an old-style header
610 </p></td></tr><tr class="answer"><td align="left" valign="top"><a name="a-ambiguous_overloads"></a></td><td align="left" valign="top"><p>
611 Another problem is the <code class="literal">rel_ops</code> namespace and the template
612 comparison operator functions contained therein. If they become
613 visible in the same namespace as other comparison functions
614 (e.g., <span class="quote">“<span class="quote">using</span>”</span> them and the &lt;iterator&gt; header),
615 then you will suddenly be faced with huge numbers of ambiguity
616 errors. This was discussed on the -v3 list; Nathan Myers
617 <a class="link" href="http://gcc.gnu.org/ml/libstdc++/2001-01/msg00247.html" target="_top">sums
618 things up here</a>. The collisions with vector/string iterator
619 types have been fixed for 3.1.
620 </p></td></tr><tr class="question" title="6.4."><td align="left" valign="top"><a name="faq.v2_headers"></a><a name="q-v2_headers"></a><p><b>6.4.</b></p></td><td align="left" valign="top"><p>
621 The g++-3 headers are <span class="emphasis"><em>not ours</em></span>
622 </p></td></tr><tr class="answer"><td align="left" valign="top"><a name="a-v2_headers"></a></td><td align="left" valign="top"><p>
623 If you are using headers in
624 <code class="filename">${prefix}/include/g++-3</code>, or if the installed
625 library's name looks like <code class="filename">libstdc++-2.10.a</code> or
626 <code class="filename">libstdc++-libc6-2.10.so</code>, then you are using the
627 old libstdc++-v2 library, which is nonstandard and
628 unmaintained. Do not report problems with -v2 to the -v3
629 mailing list.
630 </p><p>
631 For GCC versions 3.0 and 3.1 the libstdc++ header files are
632 installed in <code class="filename">${prefix}/include/g++-v3</code> (see the
633 'v'?). Starting with version 3.2 the headers are installed in
634 <code class="filename">${prefix}/include/c++/${version}</code> as this prevents
635 headers from previous versions being found by mistake.
636 </p></td></tr><tr class="question" title="6.5."><td align="left" valign="top"><a name="faq.boost_concept_checks"></a><a name="q-boost_concept_checks"></a><p><b>6.5.</b></p></td><td align="left" valign="top"><p>
637 Errors about <span class="emphasis"><em>*Concept</em></span> and
638 <span class="emphasis"><em>constraints</em></span> in the STL
639 </p></td></tr><tr class="answer"><td align="left" valign="top"><a name="a-boost_concept_checks"></a></td><td align="left" valign="top"><p>
640 If you see compilation errors containing messages about
641 <span class="errortext">foo Concept </span>and something to do with a
642 <span class="errortext">constraints</span> member function, then most
643 likely you have violated one of the requirements for types used
644 during instantiation of template containers and functions. For
645 example, EqualityComparableConcept appears if your types must be
646 comparable with == and you have not provided this capability (a
647 typo, or wrong visibility, or you just plain forgot, etc).
648 </p><p>
649 More information, including how to optionally enable/disable the
650 checks, is available in the
651 <a class="link" href="manual/bk01pt02ch05s02.html" title="Concept Checking">Diagnostics</a>.
652 chapter of the manual.
653 </p></td></tr><tr class="question" title="6.6."><td align="left" valign="top"><a name="faq.dlopen_crash"></a><a name="q-dlopen_crash"></a><p><b>6.6.</b></p></td><td align="left" valign="top"><p>
654 Program crashes when using library code in a
655 dynamically-loaded library
656 </p></td></tr><tr class="answer"><td align="left" valign="top"><a name="a-dlopen_crash"></a></td><td align="left" valign="top"><p>
657 If you are using the C++ library across dynamically-loaded
658 objects, make certain that you are passing the correct options
659 when compiling and linking:
660 </p><div class="literallayout"><p><br>
661     // compile your library components<br>
662     g++ -fPIC -c a.cc<br>
663     g++ -fPIC -c b.cc<br>
664     ...<br>
665     g++ -fPIC -c z.cc<br>
666 <br>
667     // create your library<br>
668     g++ -fPIC -shared -rdynamic -o libfoo.so a.o b.o ... z.o<br>
669 <br>
670     // link the executable<br>
671     g++ -fPIC -rdynamic -o foo ... -L. -lfoo -ldl<br>
672     </p></div></td></tr><tr class="question" title="6.7."><td align="left" valign="top"><a name="faq.memory_leaks"></a><a name="q-memory_leaks"></a><p><b>6.7.</b></p></td><td align="left" valign="top"><p>
673 <span class="quote">“<span class="quote">Memory leaks</span>”</span> in containers
674 </p></td></tr><tr class="answer"><td align="left" valign="top"><a name="a-memory_leaks"></a></td><td align="left" valign="top"><p>
675 A few people have reported that the standard containers appear
676 to leak memory when tested with memory checkers such as
677 <a class="link" href="http://valgrind.org/" target="_top">valgrind</a>.
678 Under some configurations the library's allocators keep free memory in a
679 pool for later reuse, rather than returning it to the OS. Although
680 this memory is always reachable by the library and is never
681 lost, memory debugging tools can report it as a leak. If you
682 want to test the library for memory leaks please read
683 <a class="link" href="manual/debug.html#debug.memory" title="Memory Leak Hunting">Tips for memory leak hunting</a>
684 first.
685 </p></td></tr><tr class="question" title="6.8."><td align="left" valign="top"><a name="faq.list_size_on"></a><a name="q-list_size_on"></a><p><b>6.8.</b></p></td><td align="left" valign="top"><p>
686 list::size() is O(n)!
687 </p></td></tr><tr class="answer"><td align="left" valign="top"><a name="a-list_size_on"></a></td><td align="left" valign="top"><p>
688 See
689 the <a class="link" href="manual/containers.html" title="Chapter 9.  Containers">Containers</a>
690 chapter.
691 </p></td></tr><tr class="question" title="6.9."><td align="left" valign="top"><a name="faq.easy_to_fix"></a><a name="q-easy_to_fix"></a><p><b>6.9.</b></p></td><td align="left" valign="top"><p>
692 Aw, that's easy to fix!
693 </p></td></tr><tr class="answer"><td align="left" valign="top"><a name="a-easy_to_fix"></a></td><td align="left" valign="top"><p>
694 If you have found a bug in the library and you think you have
695 a working fix, then send it in! The main GCC site has a page
696 on <a class="link" href="http://gcc.gnu.org/contribute.html" target="_top">submitting
697 patches</a> that covers the procedure, but for libstdc++ you
698 should also send the patch to our mailing list in addition to
699 the GCC patches mailing list. The libstdc++
700 <a class="link" href="manual/appendix_contributing.html" title="Appendix A.  Contributing">contributors' page</a>
701 also talks about how to submit patches.
702 </p><p>
703 In addition to the description, the patch, and the ChangeLog
704 entry, it is a Good Thing if you can additionally create a small
705 test program to test for the presence of the bug that your patch
706 fixes. Bugs have a way of being reintroduced; if an old bug
707 creeps back in, it will be caught immediately by the testsuite -
708 but only if such a test exists.
709 </p></td></tr><tr class="toc"><td align="left" valign="top" colspan="2"><dl><dt>7.1. <a href="faq.html#faq.iterator_as_pod">
710 string::iterator is not char*; vector&lt;T&gt;::iterator is not T*
711 </a></dt><dt>7.2. <a href="faq.html#faq.what_is_next">
712 What's next after libstdc++?
713 </a></dt><dt>7.3. <a href="faq.html#faq.sgi_stl">
714 What about the STL from SGI?
715 </a></dt><dt>7.4. <a href="faq.html#faq.extensions_and_backwards_compat">
716 Extensions and Backward Compatibility
717 </a></dt><dt>7.5. <a href="faq.html#faq.tr1_support">
718 Does libstdc++ support TR1?
719 </a></dt><dt>7.6. <a href="faq.html#faq.get_iso_cxx">How do I get a copy of the ISO C++ Standard?
720 </a></dt><dt>7.7. <a href="faq.html#faq.what_is_abi">
721 What's an ABI and why is it so messy?
722 </a></dt><dt>7.8. <a href="faq.html#faq.size_equals_capacity">
723 How do I make std::vector&lt;T&gt;::capacity() == std::vector&lt;T&gt;::size?
724 </a></dt></dl></td></tr><tr class="question" title="7.1."><td align="left" valign="top"><a name="faq.iterator_as_pod"></a><a name="faq.iterator_as_pod_q"></a><p><b>7.1.</b></p></td><td align="left" valign="top"><p>
725 string::iterator is not char*; vector&lt;T&gt;::iterator is not T*
726 </p></td></tr><tr class="answer"><td align="left" valign="top"><a name="faq.iterator_as_pod_a"></a></td><td align="left" valign="top"><p>
727 If you have code that depends on container&lt;T&gt; iterators
728 being implemented as pointer-to-T, your code is broken. It's
729 considered a feature, not a bug, that libstdc++ points this out.
730 </p><p>
731 While there are arguments for iterators to be implemented in
732 that manner, A) they aren't very good ones in the long term,
733 and B) they were never guaranteed by the Standard anyway. The
734 type-safety achieved by making iterators a real class rather
735 than a typedef for <span class="type">T*</span> outweighs nearly all opposing
736 arguments.
737 </p><p>
738 Code which does assume that a vector iterator <code class="varname">i</code>
739 is a pointer can often be fixed by changing <code class="varname">i</code> in
740 certain expressions to <code class="varname">&amp;*i</code>. Future revisions
741 of the Standard are expected to bless this usage for
742 vector&lt;&gt; (but not for basic_string&lt;&gt;).
743 </p></td></tr><tr class="question" title="7.2."><td align="left" valign="top"><a name="faq.what_is_next"></a><a name="q-what_is_next"></a><p><b>7.2.</b></p></td><td align="left" valign="top"><p>
744 What's next after libstdc++?
745 </p></td></tr><tr class="answer"><td align="left" valign="top"><a name="a-what_is_next"></a></td><td align="left" valign="top"><p>
746 Hopefully, not much. The goal of libstdc++ is to produce a
747 fully-compliant, fully-portable Standard Library. After that,
748 we're mostly done: there won't <span class="emphasis"><em>be</em></span> any
749 more compliance work to do.
750 </p><p>
751 There is an effort underway to add significant extensions to
752 the standard library specification. The latest version of
753 this effort is described in
754 <a class="link" href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1836.pdf" target="_top">
755 The C++ Library Technical Report 1</a>.
756 </p></td></tr><tr class="question" title="7.3."><td align="left" valign="top"><a name="faq.sgi_stl"></a><a name="q-sgi_stl"></a><p><b>7.3.</b></p></td><td align="left" valign="top"><p>
757 What about the STL from SGI?
758 </p></td></tr><tr class="answer"><td align="left" valign="top"><a name="a-sgi_stl"></a></td><td align="left" valign="top"><p>
759 The <a class="link" href="http://www.sgi.com/tech/stl/" target="_top">STL from SGI</a>,
760 version 3.3, was the final merge of the STL codebase. The
761 code in libstdc++ contains many fixes and changes, and
762 the SGI code is no longer under active
763 development. We expect that no future merges will take place.
764 </p><p>
765 In particular, <code class="classname">string</code> is not from SGI and makes no
766 use of their "rope" class (which is included as an
767 optional extension), nor is <code class="classname">valarray</code> and some others.
768 Classes like <code class="classname">vector&lt;&gt;</code> are, but have been
769 extensively modified.
770 </p><p>
771 More information on the evolution of libstdc++ can be found at the
772 <a class="link" href="manual/api.html" title="API Evolution and Deprecation History">API
773 evolution</a>
774 and <a class="link" href="manual/backwards.html" title="Backwards Compatibility">backwards
775 compatibility</a> documentation.
776 </p><p>
777 The FAQ for SGI's STL (one jump off of their main page) is
778 still recommended reading.
779 </p></td></tr><tr class="question" title="7.4."><td align="left" valign="top"><a name="faq.extensions_and_backwards_compat"></a><a name="q-extensions_and_backwards_compat"></a><p><b>7.4.</b></p></td><td align="left" valign="top"><p>
780 Extensions and Backward Compatibility
781 </p></td></tr><tr class="answer"><td align="left" valign="top"><a name="a-extensions_and_backwards_compat"></a></td><td align="left" valign="top"><p>
782 See the <a class="link" href="manual/backwards.html" title="Backwards Compatibility">link</a> on backwards compatibility and <a class="link" href="manual/api.html" title="API Evolution and Deprecation History">link</a> on evolution.
783 </p></td></tr><tr class="question" title="7.5."><td align="left" valign="top"><a name="faq.tr1_support"></a><a name="q-tr1_support"></a><p><b>7.5.</b></p></td><td align="left" valign="top"><p>
784 Does libstdc++ support TR1?
785 </p></td></tr><tr class="answer"><td align="left" valign="top"><a name="a-tr1_support"></a></td><td align="left" valign="top"><p>
786 Yes.
787 </p><p>
788 The C++ Standard Library Technical Report adds many new features to
789 the library. The latest version of this effort is described in
790 <a class="link" href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1836.pdf" target="_top">
791 Technical Report 1</a>.
792 </p><p>
793 The implementation status of TR1 in libstdc++ can be tracked <a class="link" href="manual/status.html#status.iso.tr1" title="C++ TR1">on the TR1 status
794 page</a>.
795 </p></td></tr><tr class="question" title="7.6."><td align="left" valign="top"><a name="faq.get_iso_cxx"></a><a name="q-get_iso_cxx"></a><p><b>7.6.</b></p></td><td align="left" valign="top"><p>How do I get a copy of the ISO C++ Standard?
796 </p></td></tr><tr class="answer"><td align="left" valign="top"><a name="a-get_iso_cxx"></a></td><td align="left" valign="top"><p>
797 Copies of the full ISO 14882 standard are available on line via
798 the ISO mirror site for committee members. Non-members, or those
799 who have not paid for the privilege of sitting on the committee
800 and sustained their two-meeting commitment for voting rights, may
801 get a copy of the standard from their respective national
802 standards organization. In the USA, this national standards
803 organization is ANSI and their website is
804 right <a class="link" href="http://www.ansi.org" target="_top">here</a>. (And if
805 you've already registered with them, clicking this link will take
806 you to directly to the place where you can
807 <a class="link" href="http://webstore.ansi.org/RecordDetail.aspx?sku=ISO%2FIEC+14882:2003" target="_top">buy the standard on-line</a>.
808 </p><p>
809 Who is your country's member body? Visit the
810 <a class="link" href="http://www.iso.ch/" target="_top">ISO homepage</a> and find out!
811 </p><p>
812 The 2003 version of the standard (the 1998 version plus TC1) is
813 available in print, ISBN 0-470-84674-7.
814 </p></td></tr><tr class="question" title="7.7."><td align="left" valign="top"><a name="faq.what_is_abi"></a><a name="q-what_is_abi"></a><p><b>7.7.</b></p></td><td align="left" valign="top"><p>
815 What's an ABI and why is it so messy?
816 </p></td></tr><tr class="answer"><td align="left" valign="top"><a name="a-what_is_abi"></a></td><td align="left" valign="top"><p>
817 <acronym class="acronym">ABI</acronym> stands for <span class="quote">“<span class="quote">Application Binary
818 Interface</span>”</span>. Conventionally, it refers to a great
819 mass of details about how arguments are arranged on the call
820 stack and/or in registers, and how various types are arranged
821 and padded in structs. A single CPU design may suffer
822 multiple ABIs designed by different development tool vendors
823 who made different choices, or even by the same vendor for
824 different target applications or compiler versions. In ideal
825 circumstances the CPU designer presents one ABI and all the
826 OSes and compilers use it. In practice every ABI omits
827 details that compiler implementers (consciously or
828 accidentally) must choose for themselves.
829 </p><p>
830 That ABI definition suffices for compilers to generate code so a
831 program can interact safely with an OS and its lowest-level libraries.
832 Users usually want an ABI to encompass more detail, allowing libraries
833 built with different compilers (or different releases of the same
834 compiler!) to be linked together. For C++, this includes many more
835 details than for C, and CPU designers (for good reasons elaborated
836 below) have not stepped up to publish C++ ABIs. The details include
837 virtual function implementation, struct inheritance layout, name
838 mangling, and exception handling. Such an ABI has been defined for
839 GNU C++, and is immediately useful for embedded work relying only on
840 a <span class="quote">“<span class="quote">free-standing implementation</span>”</span> that doesn't include (much
841 of) the standard library. It is a good basis for the work to come.
842 </p><p>
843 A useful C++ ABI must also incorporate many details of the standard
844 library implementation. For a C ABI, the layouts of a few structs
845 (such as FILE, stat, jmpbuf, and the like) and a few macros suffice.
846 For C++, the details include the complete set of names of functions
847 and types used, the offsets of class members and virtual functions,
848 and the actual definitions of all inlines. C++ exposes many more
849 library details to the caller than C does. It makes defining
850 a complete ABI a much bigger undertaking, and requires not just
851 documenting library implementation details, but carefully designing
852 those details so that future bug fixes and optimizations don't
853 force breaking the ABI.
854 </p><p>
855 There are ways to help isolate library implementation details from the
856 ABI, but they trade off against speed. Library details used in
857 inner loops (e.g., getchar) must be exposed and frozen for all
858 time, but many others may reasonably be kept hidden from user code,
859 so they may later be changed. Deciding which, and implementing
860 the decisions, must happen before you can reasonably document a
861 candidate C++ ABI that encompasses the standard library.
862 </p></td></tr><tr class="question" title="7.8."><td align="left" valign="top"><a name="faq.size_equals_capacity"></a><a name="q-size_equals_capacity"></a><p><b>7.8.</b></p></td><td align="left" valign="top"><p>
863 How do I make std::vector&lt;T&gt;::capacity() == std::vector&lt;T&gt;::size?
864 </p></td></tr><tr class="answer"><td align="left" valign="top"><a name="a-size_equals_capacity"></a></td><td align="left" valign="top"><p>
865 The standard idiom for deallocating a <code class="classname">vector&lt;T&gt;</code>'s
866 unused memory is to create a temporary copy of the vector and swap their
867 contents, e.g. for <code class="classname">vector&lt;T&gt; v</code>
868 </p><div class="literallayout"><p><br>
869      std::vector&lt;T&gt;(v).swap(v);<br>
870     </p></div><p>
871 The copy will take O(n) time and the swap is constant time.
872 </p><p>
873 See <a class="link" href="manual/strings.html#strings.string.shrink" title="Shrink to Fit">Shrink-to-fit
874 strings</a> for a similar solution for strings.
875 </p></td></tr></tbody></table></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="bk03.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="bk03.html">Up</a></td><td width="40%" align="right"> </td></tr><tr><td width="40%" align="left" valign="top"> </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> </td></tr></table></div></body></html>