2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libstdc++-v3 / docs / html / faq / index.html
blobf17c5d36541049c38f42ecd6e18d1a6ce9b0759a
1 <?xml version="1.0" encoding="ISO-8859-1"?>
2 <!DOCTYPE html
3 PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
6 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7 <head>
8 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
9 <meta name="KEYWORDS" content="libstdc++, libstdc++-v3, GCC, g++, libg++, STL" />
10 <meta name="DESCRIPTION" content="FAQ for the GNU libstdc++ effort." />
11 <title>libstdc++-v3 FAQ</title>
12 <link rel="StyleSheet" href="../lib3styles.css" />
13 <link rel="Start" rev="Help" href="../documentation.html" type="text/html"
14 title="GNU C++ Standard Library" />
15 <link rel="Copyright" href="../17_intro/license.html" type="text/html" />
16 <!--
17 ** Locations of "the most recent snapshot is the Nth" text are
18 ** answers 1_1, .
19 -->
20 </head>
21 <body>
23 <h1 class="centered">libstdc++ Frequently Asked Questions</h1>
25 <p class="fineprint"><em>
26 The latest version of this document is always available at
27 <a href="http://gcc.gnu.org/onlinedocs/libstdc++/faq/">
28 http://gcc.gnu.org/onlinedocs/libstdc++/faq/</a>. The main documentation
29 page is at
30 <a href="http://gcc.gnu.org/onlinedocs/libstdc++/documentation.html">
31 http://gcc.gnu.org/onlinedocs/libstdc++/documentation.html</a>.
32 </em></p>
34 <p><em>
35 To the <a href="http://gcc.gnu.org/libstdc++/">libstdc++-v3 homepage</a>.
36 </em></p>
38 <!-- ####################################################### -->
39 <hr />
40 <h1>Questions</h1>
41 <ol>
42 <li><a href="#1_0">General Information</a>
43 <!-- I suspect these will mostly be links to/into existing documents. -->
44 <ol>
45 <li><a href="#1_1">What is libstdc++-v3?</a> </li>
46 <li><a href="#1_2">Why should I use libstdc++?</a> </li>
47 <li><a href="#1_3">Who's in charge of it?</a> </li>
48 <li><a href="#1_4">How do I get libstdc++?</a> </li>
49 <li><a href="#1_5">When is libstdc++ going to be finished?</a> </li>
50 <li><a href="#1_6">How do I contribute to the effort?</a> </li>
51 <li><a href="#1_7">What happened to libg++? I need that!</a> </li>
52 <li><a href="#1_8">What if I have more questions?</a> </li>
53 <li><a href="#1_9">What are the license terms for libstdc++-v3?</a> </li>
54 </ol>
55 </li>
57 <li><a href="#2_0">Installation</a>
58 <ol>
59 <li><a href="#2_1">How do I install libstdc++-v3?</a> </li>
60 <li><a href="#2_2">[removed]</a> </li>
61 <li><a href="#2_3">What is this CVS thing that you keep
62 mentioning?</a> </li>
63 <li><a href="#2_4">How do I know if it works?</a> </li>
64 <li><a href="#2_5">This library is HUGE! And what's libsupc++?</a> </li>
65 </ol>
66 </li>
68 <li><a href="#3_0">Platform-Specific Issues</a>
69 <ol>
70 <li><a href="#3_1">Can libstdc++-v3 be used with &lt;my
71 favorite compiler&gt;?</a> </li>
72 <li><a href="#3_2">[removed]</a> </li>
73 <li><a href="#3_3">[removed]</a> </li>
74 <li><a href="#3_4">I can't use 'long long' on Solaris</a> </li>
75 <li><a href="#3_5"><code>_XOPEN_SOURCE</code> /
76 <code>_GNU_SOURCE</code> / etc is always defined</a>
77 </li>
78 <li><a href="#3_6">OS X ctype.h is broken! How can I hack it?</a></li>
79 <li><a href="#3_7">Threading is broken on i386</a></li>
80 <li><a href="#3_8">Recent GNU/Linux glibc required?</a></li>
81 <li><a href="#3_9">Can't use wchar_t/wstring on FreeBSD</a></li>
82 <li><a href="#3_10">MIPS atomic operations</a></li>
83 </ol>
84 </li>
86 <li><a href="#4_0">Known Bugs and Non-Bugs</a>
87 <ol>
88 <li><a href="#4_1">What works already?</a> </li>
89 <li><a href="#4_2">Bugs in gcc/g++ (not libstdc++-v3)</a> </li>
90 <li><a href="#4_3">Bugs in the C++ language/lib specification</a> </li>
91 <li><a href="#4_4">Things in libstdc++ that only look like bugs</a><ul>
92 <li><a href="#4_4_iostreamclear">reopening a stream fails</a> </li>
93 <li><a href="#4_4_Weff">-Weffc++ complains too much</a> </li>
94 <li><a href="#4_4_rel_ops">&quot;ambiguous overloads&quot;
95 after including an old-style header</a> </li>
96 <li><a href="#4_4_interface">The g++-3 headers are
97 <strong>not ours</strong></a> </li>
98 <li><a href="#4_4_glibc">compilation errors from streambuf.h</a> </li>
99 <li><a href="#4_4_checks">errors about <em>*Concept</em> and
100 <em>constraints</em> in the STL...</a> </li>
101 <li><a href="#4_4_dlsym">program crashes when using library code
102 in a dynamically-loaded library</a> </li>
103 <li><a href="#4_4_leak">"memory leaks" in containers</a> </li>
104 </ul>
105 </li>
106 <li><a href="#4_5">Aw, that's easy to fix!</a> </li>
107 </ol>
108 </li>
110 <li><a href="#5_0">Miscellaneous</a>
111 <ol>
112 <li><a href="#5_1">string::iterator is not char*;
113 vector&lt;T&gt;::iterator is not T*</a> </li>
114 <li><a href="#5_2">What's next after libstdc++-v3?</a> </li>
115 <li><a href="#5_3">What about the STL from SGI?</a> </li>
116 <li><a href="#5_4">Extensions and Backward Compatibility</a> </li>
117 <li><a href="#5_5">[removed]</a> </li>
118 <li><a href="#5_6">Is libstdc++-v3 thread-safe?</a> </li>
119 <li><a href="#5_7">How do I get a copy of the ISO C++ Standard?</a> </li>
120 <li><a href="#5_8">What's an ABI and why is it so messy?</a> </li>
121 <li><a href="#5_9">How do I make std::vector&lt;T&gt;::capacity()
122 == std::vector&lt;T&gt;::size?</a> </li>
123 </ol>
124 </li>
126 </ol>
128 <hr />
130 <!-- ####################################################### -->
132 <h1><a name="1_0">1.0 General Information</a></h1>
133 <!-- I suspect these will mostly be links to/into existing documents. -->
134 <h2><a name="1_1">1.1 What is libstdc++-v3?</a></h2>
135 <p>The GNU Standard C++ Library v3 is an
136 ongoing project to implement the ISO 14882 Standard C++ library
137 as described in chapters 17 through 27 and annex D. As the
138 library reaches stable plateaus, it is captured in a snapshot
139 and released. The latest release is
140 <a href="http://gcc.gnu.org/libstdc++/index.html#download">the
141 fourteenth snapshot</a> but newer versions have been included
142 in recent GCC releases. For those who want to see exactly how
143 far the project has come, or just want the latest
144 bleeding-edge code, the up-to-date source is available over
145 anonymous CVS, and can even be browsed over the Web (see
146 <a href="#1_4">1.4</a> below).
147 </p>
148 <p>The older libstdc++-v2 project is no longer maintained; the code
149 has been completely replaced and rewritten.
150 <a href="#4_4_interface">If you are using V2</a>, then you need to
151 report bugs to your system vendor, not to the V3 list.
152 </p>
153 <p>A more formal description of the V3 goals can be found in the
154 official <a href="../17_intro/DESIGN">design document</a>.
155 </p>
157 <hr />
158 <h2><a name="1_2">1.2 Why should I use libstdc++?</a></h2>
159 <p>The completion of the ISO C++ standardization gave the
160 C++ community a powerful set of reuseable tools in the form
161 of the C++ Standard Library. However, all existing C++
162 implementations are (as the Draft Standard used to say)
163 &quot;incomplet and incorrekt,&quot; and many suffer from
164 limitations of the compilers that use them.
165 </p>
166 <p>The GNU C/C++/FORTRAN/&lt;pick-a-language&gt; compiler
167 (<code>gcc</code>, <code>g++</code>, etc) is widely considered to be
168 one of the leading compilers in the world. Its development
169 has recently been taken over by the
170 <a href="http://gcc.gnu.org/">GCC team</a>. All of
171 the rapid development and near-legendary
172 <a href="http://gcc.gnu.org/gcc-3.0/buildstat.html">portability</a>
173 that are the hallmarks of an open-source project are being
174 applied to libstdc++.
175 </p>
176 <p>That means that all of the Standard classes and functions
177 (such as <code>string</code>, <code>vector&lt;&gt;</code>, iostreams,
178 and algorithms) will be freely available and fully compliant.
179 Programmers will no longer need to &quot;roll their own&quot;
180 nor be worried about platform-specific incompatibilities.
181 </p>
183 <hr />
184 <h2><a name="1_3">1.3 Who's in charge of it?</a></h2>
185 <p>The libstdc++ project is contributed to by several developers
186 all over the world, in the same way as GCC or Linux.
187 Benjamin Kosnik, Gabriel Dos Reis, Phil Edwards, Ulrich Drepper,
188 Loren James Rittle, and Paolo Carlini are the lead maintainers of
189 the CVS archive.
190 </p>
191 <p>Development and discussion is held on the libstdc++ mailing
192 list. Subscribing to the list, or searching the list
193 archives, is open to everyone. You can read instructions for
194 doing so on the <a href="http://gcc.gnu.org/libstdc++/">homepage</a>.
195 If you have questions, ideas, code, or are just curious, sign up!
196 </p>
198 <hr />
199 <h2><a name="1_4">1.4 How do I get libstdc++?</a></h2>
200 <p>The <a href="http://gcc.gnu.org/libstdc++/">homepage</a>
201 has instructions for retrieving the latest CVS sources, and for
202 browsing the CVS sources over the web.
203 </p>
204 <p>Stable versions of libstdc++-v3 are included with releases of
205 <a href="http://gcc.gnu.org/releases.html">the GCC compilers</a>.
206 </p>
207 <p>The subset commonly known as the Standard Template Library
208 (chapters 23 through 25, mostly) is adapted from the final release
209 of the SGI STL.
210 </p>
212 <hr />
213 <h2><a name="1_5">1.5 When is libstdc++ going to be finished?</a></h2>
214 <!-- <p>Nathan Myers gave the best of all possible answers in <a
215 href="http://www.deja.com/getdoc.xp?AN=469581698&fmt=text">a
216 Usenet article</a>.</p>
217 which is no longer available, thanks deja...-->
218 <p>Nathan Myers gave the best of all possible answers, responding to a
219 Usenet article asking this question: <em>Sooner, if you help.</em>
220 </p>
222 <hr />
223 <h2><a name="1_6">1.6 How do I contribute to the effort?</a></h2>
224 <p>Here is <a href="../17_intro/contribute.html">a
225 page devoted to this topic</a>. Subscribing to the mailing
226 list (see above, or the homepage) is a very good idea if you
227 have something to contribute, or if you have spare time and
228 want to help. Contributions don't have to be in the form of
229 source code; anybody who is willing to help write
230 documentation, for example, or has found a bug in code that
231 we all thought was working, is more than welcome!
232 </p>
234 <hr />
235 <h2><a name="1_7">1.7 What happened to libg++? I need that!</a></h2>
236 <p>The most recent libg++ README states that libg++ is no longer
237 being actively maintained. It should not be used for new
238 projects, and is only being kicked along to support older code.
239 </p>
240 <p>The libg++ was designed and created when there was no Standard
241 to provide guidance. Classes like linked lists are now provided
242 for by <code>list&lt;T&gt;</code> and do not need to be created by
243 <code>genclass</code>. (For that matter, templates exist now and
244 are well-supported, whereas genclass (mostly) predates them.)
245 </p>
246 <p>There are other classes in libg++ that are not specified in the
247 ISO Standard (e.g., statistical analysis). While there are a
248 lot of really useful things that are used by a lot of people
249 (e.g., statistics :-), the Standards Committee couldn't include
250 everything, and so a lot of those &quot;obvious&quot; classes
251 didn't get included.
252 </p>
253 <p>Since libstdc++ is an implementation of the Standard Library, we
254 have no plans at this time to include non-Standard utilities
255 in the implementation, however handy they are. (The extensions
256 provided in the SGI STL aren't maintained by us and don't get
257 a lot of our attention, because they don't require a lot of our
258 time.) It is entirely plausable that the &quot;useful stuff&quot;
259 from libg++ might be extracted into an updated utilities library,
260 but nobody has started such a project yet.
261 </p>
262 <p>(The <a href="http://www.boost.org/">Boost</a> site houses free
263 C++ libraries that do varying things, and happened to be started
264 by members of the Standards Committee. Certain &quot;useful
265 stuff&quot; classes will probably migrate there.)
266 </p>
267 <p>For the bold and/or desperate, the
268 <a href="http://gcc.gnu.org/extensions.html">GCC extensions page</a>
269 describes where to find the last libg++ source.
270 </p>
272 <hr />
273 <h2><a name="1_8">1.8 What if I have more questions?</a></h2>
274 <p>If you have read the README and RELEASE-NOTES files, and your
275 question remains unanswered, then just ask the mailing list.
276 At present, you do not need to be subscribed to the list to
277 send a message to it. More information is available on the
278 homepage (including how to browse the list archives); to send
279 to the list, use <a href="mailto:libstdc++@gcc.gnu.org">
280 <code>libstdc++@gcc.gnu.org</code></a>.
281 </p>
282 <p>If you have a question that you think should be included here,
283 or if you have a question <em>about</em> a question/answer here,
284 contact <a href="mailto:pme@gcc.gnu.org">Phil Edwards</a>
285 or <a href="mailto:gdr@gcc.gnu.org">Gabriel Dos Reis</a>.
286 </p>
288 <hr />
289 <h2><a name="1_9">1.9 What are the license terms for libstdc++-v3?</a></h2>
290 <p>See <a href="../17_intro/license.html">our license description</a>
291 for these and related questions.
292 </p>
294 <hr />
295 <h1><a name="2_0">2.0 Installation</a></h1>
296 <h2><a name="2_1">2.1 How do I install libstdc++-v3?</a></h2>
297 <p>Complete instructions are not given here (this is a FAQ, not
298 an installation document), but the tools required are few:
299 </p>
300 <ul>
301 <li> A 3.x release of GCC. Note that building GCC is much
302 easier and more automated than building the GCC 2.[78]
303 series was. If you are using GCC 2.95, you can still
304 build earlier snapshots of libstdc++.
305 </li>
306 <li> GNU Make is recommended, but should not be required.
307 </li>
308 <li> The GNU Autotools are needed if you are messing with
309 the configury or makefiles.
310 </li>
311 </ul>
312 <p>The file <a href="../documentation.html">documentation.html</a>
313 provides a good overview of the steps necessary to build, install,
314 and use the library. Instructions for configuring the library
315 with new flags such as --enable-threads are there also, as well as
316 patches and instructions for working with GCC 2.95.
317 </p>
318 <p>The top-level install.html and
319 <a href="../17_intro/RELEASE-NOTES">RELEASE-NOTES</a> files contain
320 the exact build and installation instructions. You may wish to
321 browse those files over CVSweb ahead of time to get a feel for
322 what's required. RELEASE-NOTES is located in the
323 &quot;.../docs/17_intro/&quot; directory of the distribution.
324 </p>
326 <hr />
327 <h2><a name="2_2">2.2 [removed]</a></h2>
328 <p>This question has become moot and has been removed. The stub
329 is here to preserve numbering (and hence links/bookmarks).
330 </p>
332 <hr />
333 <h2><a name="2_3">2.3 What is this CVS thing that you
334 keep mentioning?</a></h2>
335 <p>The <em>Concurrent Versions System</em> is one of several revision
336 control packages. It was selected for GNU projects because it's
337 free (speech), free (beer), and very high quality. The <a
338 href="http://www.gnu.org/software/cvs/cvs.html">CVS entry in
339 the GNU software catalogue</a> has a better description as
340 well as a
341 <a href="http://www.cvshome.org/">link to the makers of CVS</a>.
342 </p>
343 <p>The &quot;anonymous client checkout&quot; feature of CVS is
344 similar to anonymous FTP in that it allows anyone to retrieve
345 the latest libstdc++ sources.
346 </p>
347 <p>After the first of April, American users will have a
348 &quot;/pharmacy&quot; command-line option...
349 <!-- wonder how long that'll live -->
350 </p>
352 <hr />
353 <h2><a name="2_4">2.4 How do I know if it works?</a></h2>
354 <p>libstdc++-v3 comes with its own testsuite. You do not need
355 to actually install the library (&quot;<code>make
356 install</code>&quot;) to run the testsuite, but you do need
357 DejaGNU, as described
358 <a href="http://gcc.gnu.org/install/test.html">here</a>.
359 </p>
360 <p>To run the testsuite on the library after building it, use
361 &quot;make check&quot; while in your build directory. To run
362 the testsuite on the library after building and installing it,
363 use &quot;make check-install&quot; instead.
364 </p>
365 <p>If you find bugs in the testsuite programs themselves, or if you
366 think of a new test program that should be added to the suite,
367 <strong>please</strong> write up your idea and send it to the list!
368 </p>
370 <hr />
371 <h2><a name="2_5">2.5 This library is HUGE! And what's libsupc++?</a></h2>
372 <p>Usually the size of libraries on disk isn't noticeable. When a
373 link editor (or simply &quot;linker&quot;) pulls things from a
374 static archive library, only the necessary object files are copied
375 into your executable, not the entire library. Unfortunately, even
376 if you only need a single function or variable from an object file,
377 the entire object file is extracted. (There's nothing unique to C++
378 or libstdc++-v3 about this; it's just common behavior, given here
379 for background reasons.)
380 </p>
381 <p>Some of the object files which make up libstdc++.a are rather large.
382 If you create a statically-linked executable with
383 <code> -static</code>, those large object files are suddenly part
384 of your executable. Historically the best way around this was to
385 only place a very few functions (often only a single one) in each
386 source/object file; then extracting a single function is the same
387 as extracting a single .o file. For libstdc++-v3 this is only
388 possible to a certain extent; the object files in question contain
389 template classes and template functions, pre-instantiated, and
390 splitting those up causes severe maintenance headaches.
391 </p>
392 <p>It's not a bug, and it's not really a problem. Nevertheless, some
393 people don't like it, so here are two pseudo-solutions:
394 </p>
395 <p>If the only functions from libstdc++.a which you need are language
396 support functions (those listed in
397 <a href="../18_support/howto.html">clause 18</a> of the standard,
398 e.g., <code>new</code> and <code>delete</code>), then try linking
399 against <code>libsupc++.a</code> (usually specifying
400 <code>-lsupc++</code> when calling g++ for the final link step will
401 do it). This library contains only those support routines, one per
402 object file. But if you are using anything from the rest of the
403 library, such as IOStreams or vectors, then you'll still need
404 pieces from <code>libstdc++.a</code>.
405 </p>
406 <p>The second method is one we hope to incorporate into the library
407 build process. Some platforms can place each function and variable
408 into its own section in a .o file. The GNU linker can then perform
409 garbage collection on unused sections; this reduces the situation
410 to only copying needed functions into the executable, as before,
411 but all happens automatically.
412 </p>
413 <p>Unfortunately the garbage collection in GNU ld is buggy; sections
414 (corresponding to functions and variables) which <em>are</em> used
415 are mistakenly removed, leading to horrible crashes when your
416 executable starts up. For the time being, this feature is not used
417 when building the library.
418 </p>
420 <hr />
421 <h1><a name="3_0">3.0 Platform-Specific Issues</a></h1>
422 <h2><a name="3_1">3.1 Can libstdc++-v3 be used with &lt;my
423 favorite compiler&gt;?</a></h2>
424 <p>Probably not. Yet.</p>
425 <p>Because GCC advances so rapidly, development and testing of
426 libstdc++ is being done almost entirely under that compiler.
427 If you are curious about whether other, lesser compilers
428 (*grin*) support libstdc++, you are more than welcome to try.
429 Configuring and building the library (see above) will still
430 require certain tools, however. Also keep in mind that
431 <em>building</em> libstdc++ does not imply that your compiler
432 will be able to <em>use</em> all of the features found in the
433 C++ Standard Library.
434 </p>
435 <p>Since the goal of ISO Standardization is for all C++
436 implementations to be able to share code, the final libstdc++
437 should, in theory, be usable under any ISO-compliant
438 compiler. It will still be targeted and optimized for
439 GCC/g++, however.
440 </p>
442 <hr />
443 <h2><a name="3_2">3.2 [removed]</a></h2>
444 <p>This question has become moot and has been removed. The stub
445 is here to preserve numbering (and hence links/bookmarks).
446 </p>
448 <hr />
449 <h2><a name="3_3">3.3 [removed]</a></h2>
450 <p>This question has become moot and has been removed. The stub
451 is here to preserve numbering (and hence links/bookmarks).
452 </p>
454 <hr />
455 <h2><a name="3_4">3.4 I can't use 'long long' on Solaris</a></h2>
456 <p>By default we try to support the C99 <code>long long</code> type.
457 This requires that certain functions from your C library be present.
458 </p>
459 <p>Up through release 3.0.2 the tests performed were too general, and
460 this feature was disabled when it did not need to be. The most
461 commonly reported platform affected was Solaris.
462 </p>
463 <p>This has been fixed for 3.0.3 and onwards.
464 </p>
466 <hr />
467 <h2><a name="3_5">3.5 <code>_XOPEN_SOURCE</code> / <code>_GNU_SOURCE</code>
468 / etc is always defined</a></h2>
469 <p>On Solaris, g++ (but not gcc) always defines the preprocessor
470 macro <code>_XOPEN_SOURCE</code>. On GNU/Linux, the same happens
471 with <code>_GNU_SOURCE</code>. (This is not an exhaustive list;
472 other macros and other platforms are also affected.)
473 </p>
474 <p>These macros are typically used in C library headers, guarding new
475 versions of functions from their older versions. The C++ standard
476 library includes the C standard library, but it requires the C90
477 version, which for backwards-compatability reasons is often not the
478 default for many vendors.
479 </p>
480 <p>More to the point, the C++ standard requires behavior which is only
481 available on certain platforms after certain symbols are defined.
482 Usually the issue involves I/O-related typedefs. In order to
483 ensure correctness, the compiler simply predefines those symbols.
484 </p>
485 <p>Note that it's not enough to #define them only when the library is
486 being built (during installation). Since we don't have an 'export'
487 keyword, much of the library exists as headers, which means that
488 the symbols must also be defined as your programs are parsed and
489 compiled.
490 </p>
491 <p>To see which symbols are defined, look for CPLUSPLUS_CPP_SPEC in
492 the gcc config headers for your target (and try changing them to
493 see what happens when building complicated code). You can also run
494 <code>&quot;g++ -E -dM - &lt; /dev/null&quot;</code> to display
495 a list of predefined macros for any particular installation.
496 </p>
497 <p>This has been discussed on the mailing lists
498 <a href="http://gcc.gnu.org/cgi-bin/htsearch?method=and&amp;format=builtin-long&amp;sort=score&amp;words=_XOPEN_SOURCE+Solaris">quite a bit</a>.
499 </p>
500 <p>This method is something of a wart. We'd like to find a cleaner
501 solution, but nobody yet has contributed the time.
502 </p>
504 <hr />
505 <h2><a name="3_6">3.6 OS X ctype.h is broken! How can I hack it?</a></h2>
506 <p>This is a long-standing bug in the OS X support. Fortunately,
507 the patch is quite simple, and well-known.
508 <a href="http://gcc.gnu.org/ml/gcc/2002-03/msg00817.html"> Here's a
509 link to the solution.</a>
510 </p>
512 <hr />
513 <h2><a name="3_7">3.7 Threading is broken on i386</a></h2>
514 <p>Support for atomic integer operations is/was broken on i386
515 platforms. The assembly code accidentally used opcodes that are
516 only available on the i486 and later. So if you configured GCC
517 to target, for example, i386-linux, but actually used the programs
518 on an i686, then you would encounter no problems. Only when
519 actually running the code on a i386 will the problem appear.
520 </p>
521 <p>This is fixed in 3.2.2.
522 </p>
524 <hr />
525 <h2><a name="3_8">3.8 Recent GNU/Linux glibc required?</a></h2>
526 <p>When running on GNU/Linux, libstdc++ 3.2.1 (shared library version
527 5.0.1) and later uses localization and formatting code from the system
528 C library (glibc) version 2.2.5. That version of glibc is over a
529 year old and contains necessary bugfixes. Many GNU/Linux distros make
530 glibc version 2.3.x available now.
531 </p>
532 <p>The guideline is simple: the more recent the C++ library, the
533 more recent the C library. (This is also documented in the main
534 GCC installation instructions.)
535 </p>
537 <hr />
538 <h2><a name="3_9">3.9 Can't use wchar_t/wstring on FreeBSD</a></h2>
539 <p>At the moment there are a few problems in FreeBSD's support for
540 wide character functions, and as a result the libstdc++ configury
541 decides that wchar_t support should be disabled. Once the underlying
542 problems are fixed in FreeBSD (soon), the library support will
543 automatically enable itself.
544 </p>
545 <p>You can fix the problems yourself, and learn more about the situation,
546 by reading
547 <a href="http://gcc.gnu.org/ml/libstdc++/2003-02/subjects.html#00286">
548 this short thread</a> (&quot;_GLIBCPP_USE_WCHAR_T undefined in
549 FreeBSD's c++config.h?&quot;).
550 </p>
552 <hr />
553 <h2><a name="3_10">3.10 MIPS atomic operations</a></h2>
554 <p>The atomic locking routines for MIPS targets requires MIPS II
555 and later. A patch went in just after the 3.3 release to
556 make mips* use the generic implementation instead. You can also
557 configure for mipsel-elf as a workaround.
558 </p>
559 <p>mips*-*-linux* continues to use the MIPS II routines, and more
560 work in this area is expected.
561 </p>
563 <hr />
564 <h1><a name="4_0">4.0 Known Bugs and Non-Bugs</a></h1>
565 <em>Note that this section can get rapdily outdated -- such is the
566 nature of an open-source project. For the latest information, join
567 the mailing list or look through recent archives. The RELEASE-
568 NOTES and BUGS files are generally kept up-to-date.</em>
570 <p>For 3.0.1, the most common &quot;bug&quot; is an apparently missing
571 &quot;<code>../</code>&quot; in include/Makefile, resulting in files
572 like gthr.h and gthr-single.h not being found. Please read
573 <a href="http://gcc.gnu.org/install/configure.html">the configuration
574 instructions for GCC</a>,
575 specifically the part about configuring in a separate build directory,
576 and how strongly recommended it is. Building in the source directory
577 is fragile, is rarely tested, and tends to break, as in this case.
578 This was fixed for 3.0.2.
579 </p>
581 <p>For 3.1, the most common &quot;bug&quot; is a parse error when using
582 <code>&lt;fstream&gt;</code>, ending with a message,
583 &quot;<code>bits/basic_file.h:52: parse error before `{'
584 token</code>.&quot; Please read
585 <a href="http://gcc.gnu.org/install/">the installation instructions for
586 GCC</a>, specifically the part about not installing newer versions on
587 top of older versions. If you install 3.1 over a 3.0.x release, then
588 the wrong basic_file.h header will be found (its location changed
589 between releases).
590 </p>
592 <p><strong>Please do not report these as bugs. We know about them.</strong>
593 Reporting this -- or any other problem that's already been fixed --
594 hinders the development of GCC, because we have to take time to
595 respond to your report. Thank you.
596 </p>
598 <h2><a name="4_1">4.1 What works already?</a></h2>
599 <p>Short answer: Pretty much everything <em>works</em> except for some
600 corner cases. Also, localization is incomplete. For whether it works
601 well, or as you expect it to work, see 5.2.
602 </p>
603 <p>Long answer: See the docs/html/17_intro/CHECKLIST file, which is
604 badly outdated...
605 </p>
606 <p>What follows is a verbatim clip from the &quot;Status&quot; section
607 of the RELEASE-NOTES for the latest snapshot. For a list of
608 fixed bugs, see that file.
609 </p>
611 <!-- Yeah, I meant that "verbatim clip" thing literally... :-) -->
613 <pre>
614 New:
615 </pre>
618 <hr />
619 <h2><a name="4_2">4.2 Bugs in gcc/g++ (not libstdc++-v3)</a></h2>
620 <p>This is by no means meant to be complete nor exhaustive, but
621 mentions some problems that users may encounter when building
622 or using libstdc++. If you are experiencing one of these
623 problems, you can find more information on the libstdc++ and
624 the GCC mailing lists.
625 </p>
626 <p>Before reporting a bug, examine the
627 <a href="http://gcc.gnu.org/bugs.html">bugs database</a> with the
628 category set to &quot;libstdc++&quot;. The BUGS file in the source
629 tree also tracks known serious problems.
630 </p>
631 <ul>
632 <li>Debugging is problematic, due to bugs in line-number generation
633 (mostly fixed in the compiler) and gdb lagging behind the
634 compiler (lack of personnel). We recommend configuring the
635 compiler using <code>--with-dwarf2</code> if the DWARF2
636 debugging format is not already the default on your platform.
637 Also,
638 <a href="http://gcc.gnu.org/ml/libstdc++/2002-02/msg00034.html">changing your
639 GDB settings</a> can have a profound effect on your C++ debugging
640 experiences. :-)</li>
641 </ul>
643 <hr />
644 <h2><a name="4_3">4.3 Bugs in the C++ language/lib specification</a></h2>
645 <p>Yes, unfortunately, there are some. In a
646 <a href="http://gcc.gnu.org/ml/libstdc++/1998/msg00006.html">message
647 to the list</a>, Nathan Myers announced that he has started a list of
648 problems in the ISO C++ Standard itself, especially with
649 regard to the chapters that concern the library. The list
650 itself is
651 <a href="http://www.cantrip.org/draft-bugs.txt">posted on his
652 website</a>. Developers who are having problems interpreting
653 the Standard may wish to consult his notes.
654 </p>
655 <p>For those people who are not part of the ISO Library Group
656 (i.e., nearly all of us needing to read this page in the first
657 place :-), a public list of the library defects is occasionally
658 published <a href="http://anubis.dkuug.dk/jtc1/sc22/wg21/">here</a>.
659 Some of these have resulted in <a href="#5_2">code changes</a>.
660 </p>
662 <hr />
663 <h2><a name="4_4">4.4 Things in libstdc++ that only look like bugs</a></h2>
664 <p>There are things which are not bugs in the compiler (4.2) nor
665 the language specification (4.3), but aren't really bugs in
666 libstdc++, either. Really! Please do not report these as bugs.
667 </p>
668 <p><a name="4_4_Weff"><strong>-Weffc++</strong></a>
669 The biggest of these is the quadzillions of warnings about the
670 library headers emitted when <code>-Weffc++</code> is used. Making
671 libstdc++ &quot;-Weffc++-clean&quot; is not a goal of the project,
672 for a few reasons. Mainly, that option tries to enforce
673 object-oriented programming, while the Standard Library isn't
674 necessarily trying to be OO.
675 </p>
676 <p><a name="4_4_iostreamclear"><strong>reopening a stream fails</strong>
677 </a> Did I just say that -Weffc++ was our biggest false-bug report?
678 I lied. (It used to be.) Today it seems to be reports that after
679 executing a sequence like
680 </p>
681 <pre>
682 #include &lt;fstream&gt;
684 std::fstream fs(&quot;a_file&quot;);
685 // .
686 // . do things with fs...
687 // .
688 fs.close();
689 fs.open(&quot;a_new_file&quot;);</pre>
690 <p>all operations on the re-opened <code>fs</code> will fail, or at
691 least act very strangely. Yes, they often will, especially if
692 <code>fs</code> reached the EOF state on the previous file. The
693 reason is that the state flags are <strong>not</strong> cleared
694 on a successful call to open(). The standard unfortunately did
695 not specify behavior in this case, and to everybody's great sorrow,
696 the <a href="../ext/howto.html#5">proposed LWG resolution in
697 DR #22</a> is to leave the flags unchanged. You must insert a call
698 to <code>fs.clear()</code> between the calls to close() and open(),
699 and then everything will work like we all expect it to work.
700 </p>
701 <p><a name="4_4_rel_ops"><strong>rel_ops</strong></a>
702 Another is the <code>rel_ops</code> namespace and the template
703 comparison operator functions contained therein. If they become
704 visible in the same namespace as other comparison functions
705 (e.g., '<code>using</code>' them and the &lt;iterator&gt; header),
706 then you will suddenly be faced with huge numbers of ambiguity
707 errors. This was discussed on the -v3 list; Nathan Myers
708 <a href="http://gcc.gnu.org/ml/libstdc++/2001-01/msg00247.html">sums
709 things up here</a>. The collisions with vector/string iterator
710 types have been fixed for 3.1. <!-- more links to email here -->
711 </p>
712 <h3><a name="4_4_interface">The g++-3 headers are <em>not ours</em></a></h3>
713 <p>If you have found an extremely broken header file which is
714 causing problems for you, look carefully before submitting a
715 &quot;high&quot; priority bug report (which you probably shouldn't
716 do anyhow; see the last paragraph of the page describing
717 <a href="http://gcc.gnu.org/gnatswrite.html">the GCC bug database</a>).
718 </p>
719 <p>If the headers are in <code>${prefix}/include/g++-3</code>, or if
720 the installed library's name looks like <code>libstdc++-2.10.a</code>
721 or <code>libstdc++-libc6-2.10.so</code>, then you are using the old
722 libstdc++-v2 library, which is nonstandard and unmaintained. Do not
723 report problems with -v2 to the -v3 mailing list.
724 </p>
725 <p>For GCC versions 3.0 and 3.1 the libstdc++-v3 header files are
726 installed in <code>${prefix}/include/g++-v3</code> (see the 'v'?).
727 Starting with version 3.2 the headers are installed in
728 <code>${prefix}/include/c++/${version}</code> as this prevents
729 headers from previous versions being found by mistake.
730 </p>
731 <p><a name="4_4_glibc"><strong>glibc</strong></a>
732 If you're on a GNU/Linux system and have just upgraded to
733 glibc 2.2, but are still using gcc 2.95.2, then you should have
734 read the glibc FAQ, specifically 2.34:
735 </p>
736 <pre>
737 2.34. When compiling C++ programs, I get a compilation error in streambuf.h.
739 {BH} You are using g++ 2.95.2? After upgrading to glibc 2.2, you need to
740 apply a patch to the include files in /usr/include/g++, because the fpos_t
741 type has changed in glibc 2.2. The patch is at
742 http://clisp.cons.org/~haible/gccinclude-glibc-2.2-compat.diff
743 </pre>
744 <p>Note that 2.95.x shipped with the
745 <a href="#4_4_interface">old v2 library</a> which is no longer
746 maintained. Also note that gcc 2.95.3 fixes this problem, but
747 requires a separate patch for libstdc++-v3.
748 </p>
749 <p><a name="4_4_checks"><strong>concept checks</strong></a>
750 If you see compilation errors containing messages about
751 <code> <em>foo</em>Concept </code>and a<code> constraints </code>
752 member function, then most likely you have violated one of the
753 requirements for types used during instantiation of template
754 containers and functions. For example, EqualityComparableConcept
755 appears if your types must be comparable with == and you have not
756 provided this capability (a typo, or wrong visibility, or you
757 just plain forgot, etc).
758 </p>
759 <p>More information, including how to optionally enable/disable the
760 checks, is available
761 <a href="../19_diagnostics/howto.html#3">here</a>.
762 </p>
763 <p><a name="4_4_dlsym"><strong>dlopen/dlsym</strong></a>
764 If you are using the C++ library across dynamically-loaded
765 objects, make certain that you are passing the correct options
766 when compiling and linking:
767 </p>
768 <pre>
769 // compile your library components
770 g++ -fPIC -c a.cc
771 g++ -fPIC -c b.cc
773 g++ -fPIC -c z.cc
775 // create your library
776 g++ -fPIC -shared -rdynamic -o libfoo.so a.o b.o ... z.o
778 // link the executable
779 g++ -fPIC -rdynamic -o foo ... -L. -lfoo -ldl</pre>
780 <p><a name="4_4_leak"><strong>"memory leaks" in containers</strong></a>
781 A few people have reported that the standard containers appear
782 to leak memory when tested with memory checkers such as
783 <a href="http://developer.kde.org/~sewardj/">valgrind</a>.
784 The library's default allocators keep free memory in a pool
785 for later reuse, rather than returning it to the OS. Although
786 this memory is always reachable by the library and is never
787 lost, memory debugging tools can report it as a leak. If you
788 want to test the library for memory leaks please read
789 <a href="../debug.html#mem">Tips for memory leak hunting</a>
790 first.
791 </p>
793 <hr />
794 <h2><a name="4_5">4.5 Aw, that's easy to fix!</a></h2>
795 <p>If you have found a bug in the library and you think you have
796 a working fix, then send it in! The main GCC site has a page
797 on <a href="http://gcc.gnu.org/contribute.html">submitting
798 patches</a> that covers the procedure, but for libstdc++ you
799 should also send the patch to our mailing list in addition to
800 the GCC patches mailing list. The libstdc++
801 <a href="../17_intro/contribute.html">contributors' page</a>
802 also talks about how to submit patches.
803 </p>
804 <p>In addition to the description, the patch, and the ChangeLog
805 entry, it is a Good Thing if you can additionally create a small
806 test program to test for the presence of the bug that your
807 patch fixes. Bugs have a way of being reintroduced; if an old
808 bug creeps back in, it will be caught immediately by the
809 <a href="#2_4">testsuite</a> -- but only if such a test exists.
810 </p>
812 <hr />
813 <h1><a name="5_0">5.0 Miscellaneous</a></h1>
814 <h2><a name="5_1">5.1 string::iterator is not char*;
815 vector&lt;T&gt;::iterator is not T*</a></h2>
816 <p>If you have code that depends on container&lt;T&gt; iterators
817 being implemented as pointer-to-T, your code is broken.
818 </p>
819 <p>While there are arguments for iterators to be implemented in
820 that manner, A) they aren't very good ones in the long term,
821 and B) they were never guaranteed by the Standard anyway. The
822 type-safety achieved by making iterators a real class rather
823 than a typedef for <code>T*</code> outweighs nearly all opposing
824 arguments.
825 </p>
826 <p>Code which does assume that a vector iterator <code> i </code>
827 is a pointer can often be fixed by changing <code> i </code> in
828 certain expressions to <code> &amp;*i </code>. Future revisions
829 of the Standard are expected to bless this usage for
830 vector&lt;&gt; (but not for basic_string&lt;&gt;).
831 </p>
833 <hr />
834 <h2><a name="5_2">5.2 What's next after libstdc++-v3?</a></h2>
835 <p>Hopefully, not much. The goal of libstdc++-v3 is to produce
836 a fully-compliant, fully-portable Standard Library. After that,
837 we're mostly done: there won't <em>be</em> any more compliance
838 work to do. However:
839 </p>
840 <ol>
841 <li><p>The ISO Committee will meet periodically to review Defect Reports
842 in the C++ Standard. Undoubtedly some of these will result in
843 changes to the Standard, which will be reflected in patches to
844 libstdc++. Some of that is already happening, see 4.2. Some of
845 those changes are being predicted by the library maintainers, and
846 we add code to the library based on what the current proposed
847 resolution specifies. Those additions are listed in
848 <a href="../ext/howto.html#5">the extensions page</a>.
849 </p></li>
850 <li><p>Performance tuning. Lots of performance tuning. This too is
851 already underway for post-3.0 releases, starting with memory
852 expansion in container classes and buffer usage in synchronized
853 stream objects.
854 </p></li>
855 <li><p>An ABI for libstdc++ is being developed, so that
856 multiple binary-incompatible copies of the library can be replaced
857 with a single backwards-compatible library, like libgcc_s.so is.
858 </p></li>
859 <li><p>The current libstdc++ contains extensions to the Library which
860 must be explicitly requested by client code (for example, the
861 hash tables from SGI). Other extensions may be added to
862 libstdc++-v3 if they seem to be &quot;standard&quot; enough.
863 (For example, the &quot;long long&quot; type from C99.)
864 Bugfixes and rewrites (to improve or fix thread safety, for
865 instance) will of course be a continuing task.
866 </p></li>
867 </ol>
868 <p><a href="http://gcc.gnu.org/ml/libstdc++/1999/msg00080.html">This
869 question</a> about the next libstdc++ prompted some brief but
870 interesting
871 <a href="http://gcc.gnu.org/ml/libstdc++/1999/msg00084.html">speculation</a>.
872 </p>
874 <hr />
875 <h2><a name="5_3">5.3 What about the STL from SGI?</a></h2>
876 <p>The <a href="http://www.sgi.com/tech/stl/">STL from SGI</a>,
877 version 3.3, was the most recent merge of the STL codebase. The
878 code in libstdc++ contains many fixes and changes, and it is
879 very likely that the SGI code is no longer under active
880 development. We expect that no future merges will take place.
881 </p>
882 <p>In particular, <code>string</code> is not from SGI and makes no
883 use of their &quot;rope&quot; class (which is included as an
884 optional extension), nor is <code>valarray</code> and some others.
885 Classes like <code>vector&lt;&gt;</code> are, however we have
886 made significant changes to them since then.
887 </p>
888 <p>The FAQ for SGI's STL (one jump off of their main page) is
889 recommended reading.
890 </p>
892 <hr />
893 <h2><a name="5_4">5.4 Extensions and Backward Compatibility</a></h2>
894 <p>Headers in the <code>ext</code> and <code>backward</code>
895 subdirectories should be referred to by their relative paths:
896 <!-- Careful, the leading spaces in PRE show up directly. -->
897 </p>
898 <pre>
899 #include &lt;ext/hash_map&gt; </pre>
900 <p>rather than using <code>-I</code> or other options. This is more
901 portable and forward-compatible. (The situation is the same as
902 that of other headers whose directories are not searched directly,
903 e.g., <code>&lt;sys/stat.h&gt;</code>, <code>&lt;X11/Xlib.h&gt;</code>.
904 </p>
906 <p>The extensions are no longer in the global or <code>std</code>
907 namespaces, instead they are declared in the <code>__gnu_cxx</code>
908 namespace. For maximum portability, consider defining a namespace
909 alias to use to talk about extensions, e.g.:
910 </p>
911 <pre>
912 #ifdef __GNUC__
913 #if __GNUC__ &lt; 3
914 #include &lt;hash_map.h&gt;
915 namespace Sgi { using ::hash_map; }; // inherit globals
916 #else
917 #include &lt;ext/hash_map&gt;
918 #if __GNUC_MINOR__ == 0
919 namespace Sgi = std; // GCC 3.0
920 #else
921 namespace Sgi = ::__gnu_cxx; // GCC 3.1 and later
922 #endif
923 #endif
924 #else // ... there are other compilers, right?
925 namespace Sgi = std;
926 #endif
928 Sgi::hash_map&lt;int,int&gt; my_map; </pre>
929 <p>This is a bit cleaner than defining typedefs for all the
930 instantiations you might need.
931 </p>
932 <p><strong>Note:</strong> explicit template specializations must
933 be declared in the same namespace as the original template.
934 This means you cannot use a namespace alias when declaring
935 an explicit specialization.
936 </p>
937 <p>Extensions to the library have
938 <a href="../ext/howto.html">their own page</a>.
939 </p>
941 <hr />
942 <h2><a name="5_5">5.5 [removed]</a></h2>
943 <p>This question has become moot and has been removed. The stub
944 is here to preserve numbering (and hence links/bookmarks).
945 </p>
947 <hr />
948 <h2><a name="5_6">5.6 Is libstdc++-v3 thread-safe?</a></h2>
949 <p>libstdc++-v3 strives to be thread-safe when all of the following
950 conditions are met:
951 </p>
952 <ul>
953 <li>The system's libc is itself thread-safe,</li>
954 <li><code>gcc -v</code> reports a thread model other than 'single',</li>
955 <li>[pre-3.3 only] a non-generic implementation of atomicity.h
956 exists for the architecture in question.</li>
957 </ul>
958 <p>The user-code must guard against concurrent method calls which may
959 access any particular library object's state. Typically, the
960 application programmer may infer what object locks must be held
961 based on the objects referenced in a method call. Without getting
962 into great detail, here is an example which requires user-level
963 locks:
964 </p>
965 <pre>
966 library_class_a shared_object_a;
968 thread_main () {
969 library_class_b *object_b = new library_class_b;
970 shared_object_a.add_b (object_b); // must hold lock for shared_object_a
971 shared_object_a.mutate (); // must hold lock for shared_object_a
974 // Multiple copies of thread_main() are started in independent threads.</pre>
975 <p>Under the assumption that object_a and object_b are never exposed to
976 another thread, here is an example that should not require any
977 user-level locks:
978 </p>
979 <pre>
980 thread_main () {
981 library_class_a object_a;
982 library_class_b *object_b = new library_class_b;
983 object_a.add_b (object_b);
984 object_a.mutate ();
985 } </pre>
986 <p>All library objects are safe to use in a multithreaded program as
987 long as each thread carefully locks out access by any other
988 thread while it uses any object visible to another thread, i.e.,
989 treat library objects like any other shared resource. In general,
990 this requirement includes both read and write access to objects;
991 unless otherwise documented as safe, do not assume that two threads
992 may access a shared standard library object at the same time.
993 </p>
994 <p>See chapters <a href="../17_intro/howto.html#3">17</a> (library
995 introduction), <a href="../23_containers/howto.html#3">23</a>
996 (containers), and <a href="../27_io/howto.html#9">27</a> (I/O) for
997 more information.
998 </p>
1000 <hr />
1001 <h2><a name="5_7">5.7 How do I get a copy of the ISO C++ Standard?</a></h2>
1002 <p>Copies of the full ISO 14882 standard are available on line via the
1003 ISO mirror site for committee members. Non-members, or those who
1004 have not paid for the privilege of sitting on the committee and
1005 sustained their two-meeting commitment for voting rights, may get a
1006 copy of the standard from their respective national standards
1007 organization. In the USA, this national standards organization is
1008 ANSI and their website is right <a href="http://www.ansi.org">here</a>.
1009 (And if you've already registered with them, clicking this link will
1010 take you to directly to the place where you can
1011 <a href="http://webstore.ansi.org/ansidocstore/product.asp?sku=ISO%2FIEC+14882%2D1998">buy
1012 the standard on-line</a>.
1013 </p>
1014 <p>Who is your country's member body? Visit the
1015 <a href="http://www.iso.ch/">ISO homepage</a> and find out!
1016 </p>
1018 <hr />
1019 <h2><a name="5_8">5.8 What's an ABI and why is it so messy?</a></h2>
1020 <p>&quot;ABI&quot; stands for &quot;Application Binary Interface.&quot;
1021 Conventionally, it refers to a great mass of details about how
1022 arguments are arranged on the call stack and/or in registers, and
1023 how various types are arranged and padded in structs. A single CPU
1024 design may suffer multiple ABIs designed by different development
1025 tool vendors who made different choices, or even by the same vendor
1026 for different target applications or compiler versions. In ideal
1027 circumstances the CPU designer presents one ABI and all the OSes and
1028 compilers use it. In practice every ABI omits details that compiler
1029 implementers (consciously or accidentally) must choose for themselves.
1030 </p>
1031 <p>That ABI definition suffices for compilers to generate code so a
1032 program can interact safely with an OS and its lowest-level libraries.
1033 Users usually want an ABI to encompass more detail, allowing libraries
1034 built with different compilers (or different releases of the same
1035 compiler!) to be linked together. For C++, this includes many more
1036 details than for C, and CPU designers (for good reasons elaborated
1037 below) have not stepped up to publish C++ ABIs. The details include
1038 virtual function implementation, struct inheritance layout, name
1039 mangling, and exception handling. Such an ABI has been defined for
1040 GNU C++, and is immediately useful for embedded work relying only on
1041 a &quot;free-standing implementation&quot; that doesn't include (much
1042 of) the standard library. It is a good basis for the work to come.
1043 </p>
1044 <p>A useful C++ ABI must also incorporate many details of the standard
1045 library implementation. For a C ABI, the layouts of a few structs
1046 (such as FILE, stat, jmpbuf, and the like) and a few macros suffice.
1047 For C++, the details include the complete set of names of functions
1048 and types used, the offsets of class members and virtual functions,
1049 and the actual definitions of all inlines. C++ exposes many more
1050 library details to the caller than C does. It makes defining
1051 a complete ABI a much bigger undertaking, and requires not just
1052 documenting library implementation details, but carefully designing
1053 those details so that future bug fixes and optimizations don't
1054 force breaking the ABI.
1055 </p>
1056 <p>There are ways to help isolate library implementation details from the
1057 ABI, but they trade off against speed. Library details used in
1058 inner loops (e.g., getchar) must be exposed and frozen for all
1059 time, but many others may reasonably be kept hidden from user code,
1060 so they may later be changed. Deciding which, and implementing
1061 the decisions, must happen before you can reasonably document a
1062 candidate C++ ABI that encompasses the standard library.
1063 </p>
1065 <hr />
1066 <h2><a name="5_9">5.9 How do I make std::vector&lt;T&gt;::capacity()
1067 == std::vector&lt;T&gt;::size()?</a> </h2>
1068 <!-- referenced by 21_strings/howto.html#6 -->
1069 <p>The standard idiom for deallocating a <code>std::vector&lt;T&gt;</code>'s
1070 unused memory is to create a temporary copy of the vector and swap their
1071 contents, e.g. for <code>std::vector&lt;T&gt; v</code>
1072 </p>
1073 <pre>
1074 std::vector&lt;T&gt;(v).swap(v);
1075 </pre>
1076 <p>The copy will take O(n) time and the swap is constant time.
1077 </p>
1078 <p>See <a href='../21_strings/howto.html#6'>Shrink-to-fit strings</a> for
1079 a similar solution for strings.
1080 </p>
1082 <!-- ####################################################### -->
1084 <hr />
1085 <p class="fineprint"><em>
1086 See <a href="../17_intro/license.html">license.html</a> for copying conditions.
1087 Comments and suggestions are welcome, and may be sent to
1088 <a href="mailto:libstdc++@gcc.gnu.org">the libstdc++ mailing list</a>.
1089 </em></p>
1092 </body>
1093 </html>