1 <book xmlns="http://docbook.org/ns/docbook" version="5.0">
3 <article xml:id="faq" xreflabel="Frequently Asked Questions">
4 <?dbhtml filename="faq.html"?>
6 <info><title>Frequently Asked Questions</title>
13 <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.fsf.org">FSF</link>
18 <!-- FAQ starts here -->
21 <!-- General Information -->
22 <qandadiv xml:id="faq.info" xreflabel="General Information">
25 <qandaentry xml:id="faq.what">
26 <question xml:id="faq.what.q">
31 <answer xml:id="faq.what.a">
33 The GNU Standard C++ Library v3 is an ongoing project to
34 implement the ISO 14882 Standard C++ library as described in
35 chapters 17 through 27 and annex D. For those who want to see
36 exactly how far the project has come, or just want the latest
37 bleeding-edge code, the up-to-date source is available over
38 anonymous SVN, and can even be browsed over
39 the <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/svn.html">web</link>.
44 <qandaentry xml:id="faq.why">
45 <question xml:id="q-why">
47 Why should I use libstdc++?
50 <answer xml:id="a-why">
52 The completion of the ISO C++ standardization gave the C++
53 community a powerful set of reuseable tools in the form of the C++
54 Standard Library. However, all existing C++ implementations are
55 (as the Draft Standard used to say) <quote>incomplet and
56 incorrekt</quote>, and many suffer from limitations of the compilers
60 The GNU compiler collection
61 (<command>gcc</command>, <command>g++</command>, etc) is widely
62 considered to be one of the leading compilers in the world. Its
63 development is overseen by the
64 <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/">GCC team</link>. All of
65 the rapid development and near-legendary
66 <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/buildstat.html">portability</link>
67 that are the hallmarks of an open-source project are being
71 That means that all of the Standard classes and functions will be
72 freely available and fully compliant. (Such as
73 <classname>string</classname>,
74 <classname>vector<></classname>, iostreams, and algorithms.)
75 Programmers will no longer need to <quote>roll their own</quote>
76 nor be worried about platform-specific incompatibilities.
81 <qandaentry xml:id="faq.who">
82 <question xml:id="q-who">
84 Who's in charge of it?
87 <answer xml:id="a-who">
89 The libstdc++ project is contributed to by several developers
90 all over the world, in the same way as GCC or Linux.
91 Benjamin Kosnik, Gabriel Dos Reis, Phil Edwards, Ulrich Drepper,
92 Loren James Rittle, and Paolo Carlini are the lead maintainers of
96 Development and discussion is held on the libstdc++ mailing
97 list. Subscribing to the list, or searching the list
98 archives, is open to everyone. You can read instructions for
99 doing so on the <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/libstdc++/">homepage</link>.
100 If you have questions, ideas, code, or are just curious, sign up!
105 <qandaentry xml:id="faq.when">
106 <question xml:id="q-when">
108 When is libstdc++ going to be finished?
111 <answer xml:id="a-when">
113 Nathan Myers gave the best of all possible answers, responding to
114 a Usenet article asking this question: <emphasis>Sooner, if you
120 <qandaentry xml:id="faq.how">
121 <question xml:id="q-how">
123 How do I contribute to the effort?
126 <answer xml:id="a-how">
128 Here is <link linkend="appendix.contrib">a page devoted to
129 this topic</link>. Subscribing to the mailing list (see above, or
130 the homepage) is a very good idea if you have something to
131 contribute, or if you have spare time and want to
132 help. Contributions don't have to be in the form of source code;
133 anybody who is willing to help write documentation, for example,
134 or has found a bug in code that we all thought was working and is
135 willing to provide details, is more than welcome!
140 <qandaentry xml:id="faq.whereis_old">
141 <question xml:id="q-whereis_old">
143 What happened to the older libg++? I need that!
146 <answer xml:id="a-whereis_old">
148 The most recent libg++ README states that libg++ is no longer
149 being actively maintained. It should not be used for new
150 projects, and is only being kicked along to support older code.
153 More information in the <link linkend="manual.appendix.porting.backwards">backwards compatibility documentation</link>
158 <qandaentry xml:id="faq.more_questions">
159 <question xml:id="q-more_questions">
161 What if I have more questions?
164 <answer xml:id="a-more_questions">
166 If you have read the README file, and your question remains
167 unanswered, then just ask the mailing list. At present, you do not
168 need to be subscribed to the list to send a message to it. More
169 information is available on the homepage (including how to browse
170 the list archives); to send a message to the list,
171 use <email>libstdc++@gcc.gnu.org</email>.
175 If you have a question that you think should be included
176 here, or if you have a question <emphasis>about</emphasis> a question/answer
177 here, please send email to the libstdc++ mailing list, as above.
185 <qandadiv xml:id="faq.license" xreflabel="License QA">
188 <qandaentry xml:id="faq.license.what">
189 <question xml:id="q-license.what">
191 What are the license terms for libstdc++?
194 <answer xml:id="a-license.what">
196 See <link linkend="manual.intro.status.license">our license description</link>
197 for these and related questions.
202 <qandaentry xml:id="faq.license.any_program">
203 <question xml:id="q-license.any_program">
205 So any program which uses libstdc++ falls under the GPL?
208 <answer xml:id="a-license.any_program">
210 No. The special exception permits use of the library in
211 proprietary applications.
217 <qandaentry xml:id="faq.license.lgpl">
218 <question xml:id="q-license.lgpl">
220 How is that different from the GNU {Lesser,Library} GPL?
223 <answer xml:id="a-license.lgpl">
225 The LGPL requires that users be able to replace the LGPL code with a
226 modified version; this is trivial if the library in question is a C
227 shared library. But there's no way to make that work with C++, where
228 much of the library consists of inline functions and templates, which
229 are expanded inside the code that uses the library. So to allow people
230 to replace the library code, someone using the library would have to
231 distribute their own source, rendering the LGPL equivalent to the GPL.
236 <qandaentry xml:id="faq.license.what_restrictions">
237 <question xml:id="q-license.what_restrictions">
239 I see. So, what restrictions are there on programs that use the library?
242 <answer xml:id="a-license.what_restrictions">
244 None. We encourage such programs to be released as open source,
245 but we won't punish you or sue you if you choose otherwise.
252 <!-- Installation -->
253 <qandadiv xml:id="faq.installation" xreflabel="Installation">
256 <qandaentry xml:id="faq.how_to_install">
257 <question xml:id="q-how_to_install">
258 <para>How do I install libstdc++?
261 <answer xml:id="a-how_to_install">
263 Often libstdc++ comes pre-installed as an integral part of many
264 existing Linux and Unix systems, as well as many embedded
265 development tools. It may be necessary to install extra
266 development packages to get the headers, or the documentation, or
267 the source: please consult your vendor for details.
270 To build and install from the GNU GCC sources, please consult the
271 <link linkend="manual.intro.setup">setup
272 documentation</link> for detailed
273 instructions. You may wish to browse those files ahead
274 of time to get a feel for what's required.
279 <qandaentry xml:id="faq.how_to_get_sources">
280 <question xml:id="q-how_to_get_sources">
281 <para>How does one get current libstdc++ sources?
284 <answer xml:id="a-how_to_get_sources">
286 Libstdc++ sources for all official releases can be obtained as
287 part of the GCC sources, available from various sites and
288 mirrors. A full <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/mirrors.html">list of
289 download sites</link> is provided on the main GCC site.
292 Current libstdc++ sources can always be checked out of the main
293 GCC source repository using the appropriate version control
294 tool. At this time, that tool
295 is <application>Subversion</application>.
298 <application>Subversion</application>, or <acronym>SVN</acronym>, is
299 one of several revision control packages. It was selected for GNU
300 projects because it's free (speech), free (beer), and very high
301 quality. The <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://subversion.tigris.org"> Subversion
302 home page</link> has a better description.
305 The <quote>anonymous client checkout</quote> feature of SVN is
306 similar to anonymous FTP in that it allows anyone to retrieve
307 the latest libstdc++ sources.
311 see <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/svn.html"><acronym>SVN</acronym>
317 <qandaentry xml:id="faq.how_to_test">
318 <question xml:id="q-how_to_test">
319 <para>How do I know if it works?
322 <answer xml:id="a-how_to_test">
324 Libstdc++ comes with its own validation testsuite, which includes
325 conformance testing, regression testing, ABI testing, and
326 performance testing. Please consult the
327 <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/install/test.html">testing
328 documentation</link> for more details.
331 If you find bugs in the testsuite programs themselves, or if you
332 think of a new test program that should be added to the suite,
333 <emphasis>please</emphasis> write up your idea and send it to the list!
338 <qandaentry xml:id="faq.how_to_set_paths">
339 <question xml:id="q-how_to_set_paths">
340 <para>How do I insure that the dynamically linked library will be found?
343 <answer xml:id="a-how_to_set_paths">
345 Depending on your platform and library version, the error message might
346 be similar to one of the following:
350 ./a.out: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory
352 /usr/libexec/ld-elf.so.1: Shared object "libstdc++.so.6" not found
356 This doesn't mean that the shared library isn't installed, only
357 that the dynamic linker can't find it. When a dynamically-linked
358 executable is run the linker finds and loads the required shared
359 libraries by searching a pre-configured list of directories. If
360 the directory where you've installed libstdc++ is not in this list
361 then the libraries won't be found. The simplest way to fix this is
362 to use the <literal>LD_LIBRARY_PATH</literal> environment variable,
363 which is a colon-separated list of directories in which the linker
364 will search for shared libraries:
368 LD_LIBRARY_PATH=${prefix}/lib:$LD_LIBRARY_PATH
369 export LD_LIBRARY_PATH
373 The exact environment variable to use will depend on your
374 platform, e.g. DYLD_LIBRARY_PATH for Darwin,
375 LD_LIBRARY_PATH_32/LD_LIBRARY_PATH_64 for Solaris 32-/64-bit,
376 LD_LIBRARYN32_PATH/LD_LIBRARY64_PATH for Irix N32/64-bit ABIs and
377 SHLIB_PATH for HP-UX.
380 See the man pages for <command>ld</command>, <command>ldd</command>
381 and <command>ldconfig</command> for more information. The dynamic
382 linker has different names on different platforms but the man page
383 is usually called something such as <filename>ld.so/rtld/dld.so</filename>.
386 Using LD_LIBRARY_PATH is not always the best solution, <link linkend="manual.intro.using.linkage.dynamic">Finding Dynamic or Shared
387 Libraries</link> in the manual gives some alternatives.
392 <qandaentry xml:id="faq.what_is_libsupcxx">
393 <question xml:id="q-what_is_libsupcxx">
398 <answer xml:id="a-what_is_libsupcxx">
400 If the only functions from <filename>libstdc++.a</filename>
401 which you need are language support functions (those listed in
402 <link linkend="std.support">clause 18</link> of the
403 standard, e.g., <function>new</function> and
404 <function>delete</function>), then try linking against
405 <filename>libsupc++.a</filename>, which is a subset of
406 <filename>libstdc++.a</filename>. (Using <command>gcc</command>
407 instead of <command>g++</command> and explicitly linking in
408 <filename>libsupc++.a</filename> via <literal>-lsupc++</literal>
409 for the final link step will do it). This library contains only
410 those support routines, one per object file. But if you are
411 using anything from the rest of the library, such as IOStreams
412 or vectors, then you'll still need pieces from
413 <filename>libstdc++.a</filename>.
418 <qandaentry xml:id="faq.size">
419 <question xml:id="q-size">
421 This library is HUGE!
424 <answer xml:id="a-size">
426 Usually the size of libraries on disk isn't noticeable. When a
427 link editor (or simply <quote>linker</quote>) pulls things from a
428 static archive library, only the necessary object files are copied
429 into your executable, not the entire library. Unfortunately, even
430 if you only need a single function or variable from an object file,
431 the entire object file is extracted. (There's nothing unique to C++
432 or libstdc++ about this; it's just common behavior, given here
433 for background reasons.)
436 Some of the object files which make up libstdc++.a are rather large.
437 If you create a statically-linked executable with
438 <literal>-static</literal>, those large object files are suddenly part
439 of your executable. Historically the best way around this was to
440 only place a very few functions (often only a single one) in each
441 source/object file; then extracting a single function is the same
442 as extracting a single .o file. For libstdc++ this is only
443 possible to a certain extent; the object files in question contain
444 template classes and template functions, pre-instantiated, and
445 splitting those up causes severe maintenance headaches.
448 On supported platforms, libstdc++ takes advantage of garbage
449 collection in the GNU linker to get a result similar to separating
450 each symbol into a separate source and object files. On these platforms,
451 GNU ld can place each function and variable into its own
452 section in a .o file. The GNU linker can then perform garbage
453 collection on unused sections; this reduces the situation to only
454 copying needed functions into the executable, as before, but all
455 happens automatically.
463 <!-- Platform-Specific Issues -->
464 <qandadiv xml:id="faq.platform-specific" xreflabel="Platform-Specific Issues">
467 <qandaentry xml:id="faq.other_compilers">
468 <question xml:id="q-other_compilers">
470 Can libstdc++ be used with non-GNU compilers?
473 <answer xml:id="a-other_compilers">
478 Since the goal of ISO Standardization is for all C++
479 implementations to be able to share code, libstdc++ should be
480 usable under any ISO-compliant compiler, at least in theory.
483 However, the reality is that libstdc++ is targeted and optimized
484 for GCC/g++. This means that often libstdc++ uses specific,
485 non-standard features of g++ that are not present in older
486 versions of proprietary compilers. It may take as much as a year or two
487 after an official release of GCC that contains these features for
488 proprietary tools to support these constructs.
491 In the near past, specific released versions of libstdc++ have
492 been known to work with versions of the EDG C++ compiler, and
493 vendor-specific proprietary C++ compilers such as the Intel ICC
500 <qandaentry xml:id="faq.solaris_long_long">
501 <question xml:id="q-solaris_long_long">
503 No 'long long' type on Solaris?
506 <answer xml:id="a-solaris_long_long">
508 By default we try to support the C99 <type>long long</type> type.
509 This requires that certain functions from your C library be present.
512 Up through release 3.0.2 the platform-specific tests performed by
513 libstdc++ were too general, resulting in a conservative approach
514 to enabling the <type>long long</type> code paths. The most
515 commonly reported platform affected was Solaris.
518 This has been fixed for libstdc++ releases greater than 3.0.3.
523 <qandaentry xml:id="faq.predefined">
524 <question xml:id="q-predefined">
526 <constant>_XOPEN_SOURCE</constant> and <constant>_GNU_SOURCE</constant> are always defined?
529 <answer xml:id="a-predefined">
530 <para>On Solaris, g++ (but not gcc) always defines the preprocessor
531 macro <constant>_XOPEN_SOURCE</constant>. On GNU/Linux, the same happens
532 with <constant>_GNU_SOURCE</constant>. (This is not an exhaustive list;
533 other macros and other platforms are also affected.)
535 <para>These macros are typically used in C library headers, guarding new
536 versions of functions from their older versions. The C++ standard
537 library includes the C standard library, but it requires the C90
538 version, which for backwards-compatibility reasons is often not the
539 default for many vendors.
541 <para>More to the point, the C++ standard requires behavior which is only
542 available on certain platforms after certain symbols are defined.
543 Usually the issue involves I/O-related typedefs. In order to
544 ensure correctness, the compiler simply predefines those symbols.
546 <para>Note that it's not enough to #define them only when the library is
547 being built (during installation). Since we don't have an 'export'
548 keyword, much of the library exists as headers, which means that
549 the symbols must also be defined as your programs are parsed and
552 <para>To see which symbols are defined, look for CPLUSPLUS_CPP_SPEC in
553 the gcc config headers for your target (and try changing them to
554 see what happens when building complicated code). You can also run
555 <command>g++ -E -dM - < /dev/null"</command> to display
556 a list of predefined macros for any particular installation.
558 <para>This has been discussed on the mailing lists
559 <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/cgi-bin/htsearch?method=and&format=builtin-long&sort=score&words=_XOPEN_SOURCE+Solaris">quite a bit</link>.
561 <para>This method is something of a wart. We'd like to find a cleaner
562 solution, but nobody yet has contributed the time.
568 <qandaentry xml:id="faq.darwin_ctype">
569 <question xml:id="q-darwin_ctype">
571 Mac OS X <filename class="headerfile">ctype.h</filename> is broken! How can I fix it?
574 <answer xml:id="a-darwin_ctype">
575 <para>This is a long-standing bug in the OS X support. Fortunately,
576 the patch is quite simple, and well-known.
577 <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/ml/gcc/2002-03/msg00817.html"> Here's a
578 link to the solution</link>.
584 <qandaentry xml:id="faq.threads_i386">
585 <question xml:id="q-threads_i386">
587 Threading is broken on i386?
590 <answer xml:id="a-threads_i386">
593 <para>Support for atomic integer operations is/was broken on i386
594 platforms. The assembly code accidentally used opcodes that are
595 only available on the i486 and later. So if you configured GCC
596 to target, for example, i386-linux, but actually used the programs
597 on an i686, then you would encounter no problems. Only when
598 actually running the code on a i386 will the problem appear.
600 <para>This is fixed in 3.2.2.
606 <qandaentry xml:id="faq.atomic_mips">
607 <question xml:id="q-atomic_mips">
609 MIPS atomic operations
612 <answer xml:id="a-atomic_mips">
614 The atomic locking routines for MIPS targets requires MIPS II
615 and later. A patch went in just after the 3.3 release to
616 make mips* use the generic implementation instead. You can also
617 configure for mipsel-elf as a workaround.
620 The mips*-*-linux* port continues to use the MIPS II routines, and more
621 work in this area is expected.
626 <qandaentry xml:id="faq.linux_glibc">
627 <question xml:id="q-linux_glibc">
629 Recent GNU/Linux glibc required?
632 <answer xml:id="a-linux_glibc">
633 <para>When running on GNU/Linux, libstdc++ 3.2.1 (shared library version
634 5.0.1) and later uses localization and formatting code from the system
635 C library (glibc) version 2.2.5 which contains necessary bugfixes.
636 Most GNU/Linux distros make more recent versions available now.
637 libstdc++ 4.6.0 and later require glibc 2.3 or later for this
638 localization and formatting code.
640 <para>The guideline is simple: the more recent the C++ library, the
641 more recent the C library. (This is also documented in the main
642 GCC installation instructions.)
648 <qandaentry xml:id="faq.freebsd_wchar">
649 <question xml:id="q-freebsd_wchar">
651 Can't use wchar_t/wstring on FreeBSD
654 <answer xml:id="a-freebsd_wchar">
656 Older versions of FreeBSD's C library do not have sufficient
657 support for wide character functions, and as a result the
658 libstdc++ configury decides that wchar_t support should be
659 disabled. In addition, the libstdc++ platform checks that
660 enabled <type>wchar_t</type> were quite strict, and not granular
661 enough to detect when the minimal support to
662 enable <type>wchar_t</type> and C++ library structures
663 like <classname>wstring</classname> were present. This impacted Solaris,
664 Darwin, and BSD variants, and is fixed in libstdc++ versions post 4.1.0.
675 <qandadiv xml:id="faq.known_bugs" xreflabel="Known Bugs">
678 <qandaentry xml:id="faq.what_works">
679 <question xml:id="q-what_works">
684 <answer xml:id="a-what_works">
686 Short answer: Pretty much everything <emphasis>works</emphasis>
687 except for some corner cases. Support for localization
688 in <classname>locale</classname> may be incomplete on non-GNU
689 platforms. Also dependant on the underlying platform is support
690 for <type>wchar_t</type> and <type>long
691 long</type> specializations, and details of thread support.
694 Long answer: See the implementation status pages for
695 <link linkend="status.iso.1998">C++98</link>,
696 <link linkend="status.iso.tr1">TR1</link>, and
697 <link linkend="status.iso.200x">C++0x</link>.
702 <qandaentry xml:id="faq.standard_bugs">
703 <question xml:id="q-standard_bugs">
705 Bugs in the ISO C++ language or library specification
708 <answer xml:id="a-standard_bugs">
710 Unfortunately, there are some.
713 For those people who are not part of the ISO Library Group
714 (i.e., nearly all of us needing to read this page in the first
715 place), a public list of the library defects is occasionally
716 published <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.open-std.org/jtc1/sc22/wg21/">here</link>.
717 Some of these issues have resulted in code changes in libstdc++.
720 If you think you've discovered a new bug that is not listed,
721 please post a message describing your problem
722 to <email>libstdc++@gcc.gnu.org</email> or the Usenet group
723 comp.lang.c++.moderated.
728 <qandaentry xml:id="faq.compiler_bugs">
729 <question xml:id="q-compiler_bugs">
731 Bugs in the compiler (gcc/g++) and not libstdc++
734 <answer xml:id="a-compiler_bugs">
736 On occasion, the compiler is wrong. Please be advised that this
737 happens much less often than one would think, and avoid jumping to
741 First, examine the ISO C++ standard. Second, try another compiler
742 or an older version of the GNU compilers. Third, you can find more
743 information on the libstdc++ and the GCC mailing lists: search
744 these lists with terms describing your issue.
747 Before reporting a bug, please examine the
748 <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/bugs/">bugs database</link> with the
749 category set to <quote>g++</quote>.
756 <!-- Known Non-Bugs -->
757 <qandadiv xml:id="faq.known_non-bugs" xreflabel="Known Non-Bugs">
760 <qandaentry xml:id="faq.stream_reopening_fails">
761 <question xml:id="q-stream_reopening_fails">
763 Reopening a stream fails
766 <answer xml:id="a-stream_reopening_fails">
768 One of the most-reported non-bug reports. Executing a sequence like:
771 <literallayout class="normal">
772 #include <fstream>
774 std::fstream fs(<quote>a_file</quote>);
776 // . do things with fs...
779 fs.open(<quote>a_new_file</quote>);
783 All operations on the re-opened <varname>fs</varname> will fail, or at
784 least act very strangely. Yes, they often will, especially if
785 <varname>fs</varname> reached the EOF state on the previous file. The
786 reason is that the state flags are <emphasis>not</emphasis> cleared
787 on a successful call to open(). The standard unfortunately did
788 not specify behavior in this case, and to everybody's great sorrow,
789 the <link linkend="manual.intro.status.bugs">proposed LWG resolution in
790 DR #22</link> is to leave the flags unchanged. You must insert a call
791 to <function>fs.clear()</function> between the calls to close() and open(),
792 and then everything will work like we all expect it to work.
793 <emphasis>Update:</emphasis> for GCC 4.0 we implemented the resolution
794 of <link linkend="manual.intro.status.bugs">DR #409</link> and open()
795 now calls <function>clear()</function> on success!
800 <qandaentry xml:id="faq.wefcxx_verbose">
801 <question xml:id="q-wefcxx_verbose">
803 -Weffc++ complains too much
806 <answer xml:id="a-wefcxx_verbose">
808 Many warnings are emitted when <literal>-Weffc++</literal> is used. Making
809 libstdc++ <literal>-Weffc++</literal>-clean is not a goal of the project,
810 for a few reasons. Mainly, that option tries to enforce
811 object-oriented programming, while the Standard Library isn't
812 necessarily trying to be OO.
815 We do, however, try to have libstdc++ sources as clean as possible. If
816 you see some simple changes that pacify <literal>-Weffc++</literal>
817 without other drawbacks, send us a patch.
822 <qandaentry xml:id="faq.ambiguous_overloads">
823 <question xml:id="q-ambiguous_overloads">
825 Ambiguous overloads after including an old-style header
828 <answer xml:id="a-ambiguous_overloads">
830 Another problem is the <literal>rel_ops</literal> namespace and the template
831 comparison operator functions contained therein. If they become
832 visible in the same namespace as other comparison functions
833 (e.g., <quote>using</quote> them and the <iterator> header),
834 then you will suddenly be faced with huge numbers of ambiguity
835 errors. This was discussed on the -v3 list; Nathan Myers
836 <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/ml/libstdc++/2001-01/msg00247.html">sums
837 things up here</link>. The collisions with vector/string iterator
838 types have been fixed for 3.1.
843 <qandaentry xml:id="faq.v2_headers">
844 <question xml:id="q-v2_headers">
846 The g++-3 headers are <emphasis>not ours</emphasis>
849 <answer xml:id="a-v2_headers">
851 If you are using headers in
852 <filename>${prefix}/include/g++-3</filename>, or if the installed
853 library's name looks like <filename>libstdc++-2.10.a</filename> or
854 <filename>libstdc++-libc6-2.10.so</filename>, then you are using the
855 old libstdc++-v2 library, which is nonstandard and
856 unmaintained. Do not report problems with -v2 to the -v3
860 For GCC versions 3.0 and 3.1 the libstdc++ header files are
861 installed in <filename>${prefix}/include/g++-v3</filename> (see the
862 'v'?). Starting with version 3.2 the headers are installed in
863 <filename>${prefix}/include/c++/${version}</filename> as this prevents
864 headers from previous versions being found by mistake.
870 <qandaentry xml:id="faq.boost_concept_checks">
871 <question xml:id="q-boost_concept_checks">
873 Errors about <emphasis>*Concept</emphasis> and
874 <emphasis>constraints</emphasis> in the STL
877 <answer xml:id="a-boost_concept_checks">
879 If you see compilation errors containing messages about
880 <errortext>foo Concept </errortext>and something to do with a
881 <errortext>constraints</errortext> member function, then most
882 likely you have violated one of the requirements for types used
883 during instantiation of template containers and functions. For
884 example, EqualityComparableConcept appears if your types must be
885 comparable with == and you have not provided this capability (a
886 typo, or wrong visibility, or you just plain forgot, etc).
889 More information, including how to optionally enable/disable the
890 checks, is available in the
891 <link linkend="std.diagnostics.concept_checking">Diagnostics</link>.
892 chapter of the manual.
897 <qandaentry xml:id="faq.dlopen_crash">
898 <question xml:id="q-dlopen_crash">
900 Program crashes when using library code in a
901 dynamically-loaded library
904 <answer xml:id="a-dlopen_crash">
906 If you are using the C++ library across dynamically-loaded
907 objects, make certain that you are passing the correct options
908 when compiling and linking:
911 <literallayout class="normal">
912 // compile your library components
918 // create your library
919 g++ -fPIC -shared -rdynamic -o libfoo.so a.o b.o ... z.o
921 // link the executable
922 g++ -fPIC -rdynamic -o foo ... -L. -lfoo -ldl
927 <qandaentry xml:id="faq.memory_leaks">
928 <question xml:id="q-memory_leaks">
930 <quote>Memory leaks</quote> in containers
933 <answer xml:id="a-memory_leaks">
935 A few people have reported that the standard containers appear
936 to leak memory when tested with memory checkers such as
937 <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://valgrind.org/">valgrind</link>.
938 The library's default allocators keep free memory in a pool
939 for later reuse, rather than returning it to the OS. Although
940 this memory is always reachable by the library and is never
941 lost, memory debugging tools can report it as a leak. If you
942 want to test the library for memory leaks please read
943 <link linkend="debug.memory">Tips for memory leak hunting</link>
949 <qandaentry xml:id="faq.list_size_on">
950 <question xml:id="q-list_size_on">
952 list::size() is O(n)!
955 <answer xml:id="a-list_size_on">
958 the <link linkend="std.containers">Containers</link>
964 <qandaentry xml:id="faq.easy_to_fix">
965 <question xml:id="q-easy_to_fix">
967 Aw, that's easy to fix!
970 <answer xml:id="a-easy_to_fix">
972 If you have found a bug in the library and you think you have
973 a working fix, then send it in! The main GCC site has a page
974 on <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/contribute.html">submitting
975 patches</link> that covers the procedure, but for libstdc++ you
976 should also send the patch to our mailing list in addition to
977 the GCC patches mailing list. The libstdc++
978 <link linkend="appendix.contrib">contributors' page</link>
979 also talks about how to submit patches.
982 In addition to the description, the patch, and the ChangeLog
983 entry, it is a Good Thing if you can additionally create a small
984 test program to test for the presence of the bug that your patch
985 fixes. Bugs have a way of being reintroduced; if an old bug
986 creeps back in, it will be caught immediately by the testsuite -
987 but only if such a test exists.
995 <!-- Miscellaneous -->
996 <qandadiv xml:id="faq.misc" xreflabel="Miscellaneous">
999 <qandaentry xml:id="faq.iterator_as_pod">
1000 <question xml:id="faq.iterator_as_pod_q">
1002 string::iterator is not char*; vector<T>::iterator is not T*
1005 <answer xml:id="faq.iterator_as_pod_a">
1007 If you have code that depends on container<T> iterators
1008 being implemented as pointer-to-T, your code is broken. It's
1009 considered a feature, not a bug, that libstdc++ points this out.
1012 While there are arguments for iterators to be implemented in
1013 that manner, A) they aren't very good ones in the long term,
1014 and B) they were never guaranteed by the Standard anyway. The
1015 type-safety achieved by making iterators a real class rather
1016 than a typedef for <type>T*</type> outweighs nearly all opposing
1020 Code which does assume that a vector iterator <varname>i</varname>
1021 is a pointer can often be fixed by changing <varname>i</varname> in
1022 certain expressions to <varname>&*i</varname>. Future revisions
1023 of the Standard are expected to bless this usage for
1024 vector<> (but not for basic_string<>).
1029 <qandaentry xml:id="faq.what_is_next">
1030 <question xml:id="q-what_is_next">
1032 What's next after libstdc++?
1035 <answer xml:id="a-what_is_next">
1037 Hopefully, not much. The goal of libstdc++ is to produce a
1038 fully-compliant, fully-portable Standard Library. After that,
1039 we're mostly done: there won't <emphasis>be</emphasis> any
1040 more compliance work to do.
1043 There is an effort underway to add significant extensions to
1044 the standard library specification. The latest version of
1045 this effort is described in
1046 <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1836.pdf">
1047 The C++ Library Technical Report 1</link>.
1052 <qandaentry xml:id="faq.sgi_stl">
1053 <question xml:id="q-sgi_stl">
1055 What about the STL from SGI?
1058 <answer xml:id="a-sgi_stl">
1060 The <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.sgi.com/tech/stl/">STL from SGI</link>,
1061 version 3.3, was the final merge of the STL codebase. The
1062 code in libstdc++ contains many fixes and changes, and
1063 the SGI code is no longer under active
1064 development. We expect that no future merges will take place.
1067 In particular, <classname>string</classname> is not from SGI and makes no
1068 use of their "rope" class (which is included as an
1069 optional extension), nor is <classname>valarray</classname> and some others.
1070 Classes like <classname>vector<></classname> are, but have been
1071 extensively modified.
1074 More information on the evolution of libstdc++ can be found at the
1075 <link linkend="appendix.porting.api">API
1077 and <link linkend="manual.appendix.porting.backwards">backwards
1078 compatibility</link> documentation.
1081 The FAQ for SGI's STL (one jump off of their main page) is
1082 still recommended reading.
1087 <qandaentry xml:id="faq.extensions_and_backwards_compat">
1088 <question xml:id="q-extensions_and_backwards_compat">
1090 Extensions and Backward Compatibility
1093 <answer xml:id="a-extensions_and_backwards_compat">
1095 See the <link linkend="manual.appendix.porting.backwards">link</link> on backwards compatibility and <link linkend="appendix.porting.api">link</link> on evolution.
1100 <qandaentry xml:id="faq.tr1_support">
1101 <question xml:id="q-tr1_support">
1103 Does libstdc++ support TR1?
1106 <answer xml:id="a-tr1_support">
1111 The C++ Standard Library Technical Report adds many new features to
1112 the library. The latest version of this effort is described in
1113 <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1836.pdf">
1114 Technical Report 1</link>.
1117 The implementation status of TR1 in libstdc++ can be tracked <link linkend="status.iso.tr1">on the TR1 status
1123 <qandaentry xml:id="faq.get_iso_cxx">
1124 <question xml:id="q-get_iso_cxx">
1125 <para>How do I get a copy of the ISO C++ Standard?
1128 <answer xml:id="a-get_iso_cxx">
1130 Copies of the full ISO 14882 standard are available on line via
1131 the ISO mirror site for committee members. Non-members, or those
1132 who have not paid for the privilege of sitting on the committee
1133 and sustained their two-meeting commitment for voting rights, may
1134 get a copy of the standard from their respective national
1135 standards organization. In the USA, this national standards
1136 organization is ANSI and their website is
1137 right <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.ansi.org">here</link>. (And if
1138 you've already registered with them, clicking this link will take
1139 you to directly to the place where you can
1140 <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://webstore.ansi.org/RecordDetail.aspx?sku=ISO%2FIEC+14882:2003">buy the standard on-line</link>.
1143 Who is your country's member body? Visit the
1144 <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.iso.ch/">ISO homepage</link> and find out!
1147 The 2003 version of the standard (the 1998 version plus TC1) is
1148 available in print, ISBN 0-470-84674-7.
1153 <qandaentry xml:id="faq.what_is_abi">
1154 <question xml:id="q-what_is_abi">
1156 What's an ABI and why is it so messy?
1159 <answer xml:id="a-what_is_abi">
1161 <acronym>ABI</acronym> stands for <quote>Application Binary
1162 Interface</quote>. Conventionally, it refers to a great
1163 mass of details about how arguments are arranged on the call
1164 stack and/or in registers, and how various types are arranged
1165 and padded in structs. A single CPU design may suffer
1166 multiple ABIs designed by different development tool vendors
1167 who made different choices, or even by the same vendor for
1168 different target applications or compiler versions. In ideal
1169 circumstances the CPU designer presents one ABI and all the
1170 OSes and compilers use it. In practice every ABI omits
1171 details that compiler implementers (consciously or
1172 accidentally) must choose for themselves.
1175 That ABI definition suffices for compilers to generate code so a
1176 program can interact safely with an OS and its lowest-level libraries.
1177 Users usually want an ABI to encompass more detail, allowing libraries
1178 built with different compilers (or different releases of the same
1179 compiler!) to be linked together. For C++, this includes many more
1180 details than for C, and CPU designers (for good reasons elaborated
1181 below) have not stepped up to publish C++ ABIs. The details include
1182 virtual function implementation, struct inheritance layout, name
1183 mangling, and exception handling. Such an ABI has been defined for
1184 GNU C++, and is immediately useful for embedded work relying only on
1185 a <quote>free-standing implementation</quote> that doesn't include (much
1186 of) the standard library. It is a good basis for the work to come.
1189 A useful C++ ABI must also incorporate many details of the standard
1190 library implementation. For a C ABI, the layouts of a few structs
1191 (such as FILE, stat, jmpbuf, and the like) and a few macros suffice.
1192 For C++, the details include the complete set of names of functions
1193 and types used, the offsets of class members and virtual functions,
1194 and the actual definitions of all inlines. C++ exposes many more
1195 library details to the caller than C does. It makes defining
1196 a complete ABI a much bigger undertaking, and requires not just
1197 documenting library implementation details, but carefully designing
1198 those details so that future bug fixes and optimizations don't
1199 force breaking the ABI.
1202 There are ways to help isolate library implementation details from the
1203 ABI, but they trade off against speed. Library details used in
1204 inner loops (e.g., getchar) must be exposed and frozen for all
1205 time, but many others may reasonably be kept hidden from user code,
1206 so they may later be changed. Deciding which, and implementing
1207 the decisions, must happen before you can reasonably document a
1208 candidate C++ ABI that encompasses the standard library.
1213 <qandaentry xml:id="faq.size_equals_capacity">
1214 <question xml:id="q-size_equals_capacity">
1216 How do I make std::vector<T>::capacity() == std::vector<T>::size?
1219 <answer xml:id="a-size_equals_capacity">
1221 The standard idiom for deallocating a <classname>vector<T></classname>'s
1222 unused memory is to create a temporary copy of the vector and swap their
1223 contents, e.g. for <classname>vector<T> v</classname>
1225 <literallayout class="normal">
1226 std::vector<T>(v).swap(v);
1229 The copy will take O(n) time and the swap is constant time.
1232 See <link linkend="strings.string.shrink">Shrink-to-fit
1233 strings</link> for a similar solution for strings.
1241 <!-- FAQ ends here -->