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