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 -->
19 <qandaset xml:id="faq.faq">
21 <!-- General Information -->
22 <qandadiv xml:id="faq.info" xreflabel="General Information">
24 <qandaentry xml:id="faq.what">
25 <question xml:id="faq.what.q">
30 <answer xml:id="faq.what.a">
32 The GNU Standard C++ Library v3 is an ongoing project to
33 implement the ISO 14882 Standard C++ library as described in
34 clauses 17 through 30 and annex D. For those who want to see
35 exactly how far the project has come, or just want the latest
36 bleeding-edge code, the up-to-date source is available over
37 anonymous SVN, and can be browsed over
38 the <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://gcc.gnu.org/svn.html">web</link>.
43 <qandaentry xml:id="faq.why">
44 <question xml:id="q-why">
46 Why should I use libstdc++?
49 <answer xml:id="a-why">
51 The completion of the initial ISO C++ standardization effort gave the C++
52 community a powerful set of reuseable tools in the form of the C++
53 Standard Library. However, for several years C++ implementations were
54 (as the Draft Standard used to say) <quote>incomplet and
55 incorrekt</quote>, and many suffered from limitations of the compilers
59 The GNU compiler collection
60 (<command>gcc</command>, <command>g++</command>, etc) is widely
61 considered to be one of the leading compilers in the world. Its
62 development is overseen by the
63 <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://gcc.gnu.org/">GCC team</link>. All of
64 the rapid development and near-legendary
65 <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://gcc.gnu.org/buildstat.html">portability</link>
66 that are the hallmarks of an open-source project are applied to libstdc++.
69 All of the standard classes and functions from C++98/C++03
70 (such as <classname>string</classname>,
71 <classname>vector<></classname>, iostreams, algorithms etc.)
72 are freely available and atempt to be fully compliant.
73 Work is ongoing to complete support for the current revision of the
79 <qandaentry xml:id="faq.who">
80 <question xml:id="q-who">
82 Who's in charge of it?
85 <answer xml:id="a-who">
87 The libstdc++ project is contributed to by several developers
88 all over the world, in the same way as GCC or the Linux kernel.
89 The current maintainers are listed in the
90 <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://gcc.gnu.org/viewcvs/gcc/trunk/MAINTAINERS?view=co"><filename>MAINTAINERS</filename></link>
91 file (look for "c++ runtime libs").
94 Development and discussion is held on the libstdc++ mailing
95 list. Subscribing to the list, or searching the list
96 archives, is open to everyone. You can read instructions for
97 doing so on the <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://gcc.gnu.org/lists.html">GCC mailing lists</link> page.
98 If you have questions, ideas, code, or are just curious, sign up!
103 <qandaentry xml:id="faq.when">
104 <question xml:id="q-when">
106 When is libstdc++ going to be finished?
109 <answer xml:id="a-when">
111 Nathan Myers gave the best of all possible answers, responding to
112 a Usenet article asking this question: <emphasis>Sooner, if you
118 <qandaentry xml:id="faq.how">
119 <question xml:id="q-how">
121 How do I contribute to the effort?
124 <answer xml:id="a-how">
126 See the <link linkend="appendix.contrib">Contributing</link> section in
127 the manual. Subscribing to the mailing list (see above, or
128 the homepage) is a very good idea if you have something to
129 contribute, or if you have spare time and want to
130 help. Contributions don't have to be in the form of source code;
131 anybody who is willing to help write documentation, for example,
132 or has found a bug in code that we all thought was working and is
133 willing to provide details, is more than welcome!
138 <qandaentry xml:id="faq.whereis_old">
139 <question xml:id="q-whereis_old">
141 What happened to the older libg++? I need that!
144 <answer xml:id="a-whereis_old">
146 The last libg++ README states
147 <quote>This package is considered obsolete and is no longer
148 being developed.</quote>
149 It should not be used for new projects, and won't even compile with
150 recent releases of GCC (or most other C++ compilers).
153 More information can be found in the
154 <link linkend="manual.appendix.porting.backwards">Backwards
155 Compatibility</link> section of the libstdc++ manual.
160 <qandaentry xml:id="faq.more_questions">
161 <question xml:id="q-more_questions">
163 What if I have more questions?
166 <answer xml:id="a-more_questions">
168 If you have read the documentation, and your question remains
169 unanswered, then just ask the mailing list. At present, you do not
170 need to be subscribed to the list to send a message to it. More
171 information is available on the homepage (including how to browse
172 the list archives); to send a message to the list,
173 use <email>libstdc++@gcc.gnu.org</email>.
177 If you have a question that you think should be included
178 here, or if you have a question <emphasis>about</emphasis> a question/answer
179 here, please send email to the libstdc++ mailing list, as above.
187 <qandadiv xml:id="faq.license" xreflabel="License QA">
190 <qandaentry xml:id="faq.license.what">
191 <question xml:id="q-license.what">
193 What are the license terms for libstdc++?
196 <answer xml:id="a-license.what">
198 See <link linkend="manual.intro.status.license">our license description</link>
199 for these and related questions.
204 <qandaentry xml:id="faq.license.any_program">
205 <question xml:id="q-license.any_program">
207 So any program which uses libstdc++ falls under the GPL?
210 <answer xml:id="a-license.any_program">
212 No. The special exception permits use of the library in
213 proprietary applications.
219 <qandaentry xml:id="faq.license.lgpl">
220 <question xml:id="q-license.lgpl">
222 How is that different from the GNU {Lesser,Library} GPL?
225 <answer xml:id="a-license.lgpl">
227 The LGPL requires that users be able to replace the LGPL code with a
228 modified version; this is trivial if the library in question is a C
229 shared library. But there's no way to make that work with C++, where
230 much of the library consists of inline functions and templates, which
231 are expanded inside the code that uses the library. So to allow people
232 to replace the library code, someone using the library would have to
233 distribute their own source, rendering the LGPL equivalent to the GPL.
238 <qandaentry xml:id="faq.license.what_restrictions">
239 <question xml:id="q-license.what_restrictions">
241 I see. So, what restrictions are there on programs that use the library?
244 <answer xml:id="a-license.what_restrictions">
246 None. We encourage such programs to be released as free software,
247 but we won't punish you or sue you if you choose otherwise.
254 <!-- Installation -->
255 <qandadiv xml:id="faq.installation" xreflabel="Installation">
258 <qandaentry xml:id="faq.how_to_install">
259 <question xml:id="q-how_to_install">
260 <para>How do I install libstdc++?
263 <answer xml:id="a-how_to_install">
265 Often libstdc++ comes pre-installed as an integral part of many
266 existing GNU/Linux and Unix systems, as well as many embedded
267 development tools. It may be necessary to install extra
268 development packages to get the headers, or the documentation, or
269 the source: please consult your vendor for details.
272 To build and install from the GNU GCC sources, please consult the
273 <link linkend="manual.intro.setup">setup
274 documentation</link> for detailed
275 instructions. You may wish to browse those files ahead
276 of time to get a feel for what's required.
281 <qandaentry xml:id="faq.how_to_get_sources">
282 <question xml:id="q-how_to_get_sources">
283 <para>How does one get current libstdc++ sources?
286 <answer xml:id="a-how_to_get_sources">
288 Libstdc++ sources for all official releases can be obtained as
289 part of the GCC sources, available from various sites and
290 mirrors. A full <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://gcc.gnu.org/mirrors.html">list of
291 download sites</link> is provided on the main GCC site.
294 Current libstdc++ sources can always be checked out of the main
295 GCC source repository using the appropriate version control
296 tool. At this time, that tool
297 is <application>Subversion</application>.
300 <application>Subversion</application>, or <acronym>SVN</acronym>, is
301 one of several revision control packages. It was selected for GNU
302 projects because it's free (speech), free (beer), and very high
303 quality. The <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://subversion.tigris.org"> Subversion
304 home page</link> has a better description.
307 The <quote>anonymous client checkout</quote> feature of SVN is
308 similar to anonymous FTP in that it allows anyone to retrieve
309 the latest libstdc++ sources.
313 see <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://gcc.gnu.org/svn.html"><acronym>SVN</acronym>
319 <qandaentry xml:id="faq.how_to_test">
320 <question xml:id="q-how_to_test">
321 <para>How do I know if it works?
324 <answer xml:id="a-how_to_test">
326 Libstdc++ comes with its own validation testsuite, which includes
327 conformance testing, regression testing, ABI testing, and
328 performance testing. Please consult the
329 <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/install/test.html">testing
330 documentation</link> for GCC and
331 <link linkend="manual.intro.setup.test">Test</link> in the libstdc++
332 manual for more details.
335 If you find bugs in the testsuite programs themselves, or if you
336 think of a new test program that should be added to the suite,
337 <emphasis>please</emphasis> write up your idea and send it to the list!
342 <qandaentry xml:id="faq.how_to_set_paths">
343 <question xml:id="q-how_to_set_paths">
344 <para>How do I insure that the dynamically linked library will be found?
347 <answer xml:id="a-how_to_set_paths">
349 Depending on your platform and library version, the error message might
350 be similar to one of the following:
354 ./a.out: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory
356 /usr/libexec/ld-elf.so.1: Shared object "libstdc++.so.6" not found
360 This doesn't mean that the shared library isn't installed, only
361 that the dynamic linker can't find it. When a dynamically-linked
362 executable is run the linker finds and loads the required shared
363 libraries by searching a pre-configured list of directories. If
364 the directory where you've installed libstdc++ is not in this list
365 then the libraries won't be found.
369 If you already have an older version of libstdc++ installed then the
370 error might look like one of the following instead:
374 ./a.out: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.20' not found
375 ./a.out: /usr/lib/libstdc++.so.6: version `CXXABI_1.3.8' not found
379 This means the linker found <filename>/usr/lib/libstdc++.so.6</filename>
380 but that library belongs to an older version of GCC than was used to
381 compile and link the program <filename>a.out</filename> (or some part
382 of it). The program depends on code defined in the newer libstdc++
383 that belongs to the newer version of GCC, so the linker must be told
384 how to find the newer libstdc++ shared library.
388 The simplest way to fix this is
389 to use the <envar>LD_LIBRARY_PATH</envar> environment variable,
390 which is a colon-separated list of directories in which the linker
391 will search for shared libraries:
395 export LD_LIBRARY_PATH=${prefix}/lib:$LD_LIBRARY_PATH
399 Here the shell variable <varname>${prefix}</varname> is assumed to contain
400 the directory prefix where GCC was installed to. The directory containing
401 the library might depend on whether you want the 32-bit or 64-bit copy
402 of the library, so for example would be
403 <filename class="directory">${prefix}/lib64</filename> on some systems.
404 The exact environment variable to use will depend on your
405 platform, e.g. <envar>DYLD_LIBRARY_PATH</envar> for Darwin,
406 <envar>LD_LIBRARY_PATH_32</envar>/<envar>LD_LIBRARY_PATH_64</envar>
407 for Solaris 32-/64-bit,
408 and <envar>SHLIB_PATH</envar> for HP-UX.
411 See the man pages for <command>ld</command>, <command>ldd</command>
412 and <command>ldconfig</command> for more information. The dynamic
413 linker has different names on different platforms but the man page
414 is usually called something such as <filename>ld.so</filename>,
415 <filename>rtld</filename> or <filename>dld.so</filename>.
418 Using <envar>LD_LIBRARY_PATH</envar> is not always the best solution,
419 <link linkend="manual.intro.using.linkage.dynamic">Finding Dynamic or Shared
420 Libraries</link> in the manual gives some alternatives.
425 <qandaentry xml:id="faq.what_is_libsupcxx">
426 <question xml:id="q-what_is_libsupcxx">
431 <answer xml:id="a-what_is_libsupcxx">
433 If the only functions from <filename class="libraryfile">libstdc++.a</filename>
434 which you need are language support functions (those listed in
435 <link linkend="std.support">clause 18</link> of the
436 standard, e.g., <function>new</function> and
437 <function>delete</function>), then try linking against
438 <filename class="libraryfile">libsupc++.a</filename>, which is a subset of
439 <filename class="libraryfile">libstdc++.a</filename>. (Using <command>gcc</command>
440 instead of <command>g++</command> and explicitly linking in
441 <filename class="libraryfile">libsupc++.a</filename> via <option>-lsupc++</option>
442 for the final link step will do it). This library contains only
443 those support routines, one per object file. But if you are
444 using anything from the rest of the library, such as IOStreams
445 or vectors, then you'll still need pieces from
446 <filename class="libraryfile">libstdc++.a</filename>.
451 <qandaentry xml:id="faq.size">
452 <question xml:id="q-size">
454 This library is HUGE!
457 <answer xml:id="a-size">
459 Usually the size of libraries on disk isn't noticeable. When a
460 link editor (or simply <quote>linker</quote>) pulls things from a
461 static archive library, only the necessary object files are copied
462 into your executable, not the entire library. Unfortunately, even
463 if you only need a single function or variable from an object file,
464 the entire object file is extracted. (There's nothing unique to C++
465 or libstdc++ about this; it's just common behavior, given here
466 for background reasons.)
469 Some of the object files which make up
470 <filename class="libraryfile">libstdc++.a</filename> are rather large.
471 If you create a statically-linked executable with
472 <option>-static</option>, those large object files are suddenly part
473 of your executable. Historically the best way around this was to
474 only place a very few functions (often only a single one) in each
475 source/object file; then extracting a single function is the same
476 as extracting a single <filename>.o</filename> file. For libstdc++ this
477 is only possible to a certain extent; the object files in question contain
478 template classes and template functions, pre-instantiated, and
479 splitting those up causes severe maintenance headaches.
482 On supported platforms, libstdc++ takes advantage of garbage
483 collection in the GNU linker to get a result similar to separating
484 each symbol into a separate source and object files. On these platforms,
485 GNU ld can place each function and variable into its own
486 section in a <filename>.o</filename> file. The GNU linker can then perform
487 garbage collection on unused sections; this reduces the situation to only
488 copying needed functions into the executable, as before, but all
489 happens automatically.
497 <!-- Platform-Specific Issues -->
498 <qandadiv xml:id="faq.platform-specific" xreflabel="Platform-Specific Issues">
501 <qandaentry xml:id="faq.other_compilers">
502 <question xml:id="q-other_compilers">
504 Can libstdc++ be used with non-GNU compilers?
507 <answer xml:id="a-other_compilers">
512 Since the goal of ISO Standardization is for all C++
513 implementations to be able to share code, libstdc++ should be
514 usable under any ISO-compliant compiler, at least in theory.
517 However, the reality is that libstdc++ is targeted and optimized
518 for GCC/G++. This means that often libstdc++ uses specific,
519 non-standard features of G++ that are not present in older
520 versions of proprietary compilers. It may take as much as a year or two
521 after an official release of GCC that contains these features for
522 proprietary tools to support these constructs.
525 Recent versions of libstdc++ are known to work with the Clang compiler.
526 In the near past, specific released versions of libstdc++ have
527 been known to work with versions of the EDG C++ compiler, and
528 vendor-specific proprietary C++ compilers such as the Intel ICC
535 <qandaentry xml:id="faq.solaris_long_long">
536 <question xml:id="q-solaris_long_long">
538 No '<type>long long</type>' type on Solaris?
541 <answer xml:id="a-solaris_long_long">
543 By default we try to support the C99 <type>long long</type> type.
544 This requires that certain functions from your C library be present.
547 Up through release 3.0.2 the platform-specific tests performed by
548 libstdc++ were too general, resulting in a conservative approach
549 to enabling the <type>long long</type> code paths. The most
550 commonly reported platform affected was Solaris.
553 This has been fixed for libstdc++ releases greater than 3.0.3.
558 <qandaentry xml:id="faq.predefined">
559 <question xml:id="q-predefined">
561 <constant>_XOPEN_SOURCE</constant> and <constant>_GNU_SOURCE</constant> are always defined?
564 <answer xml:id="a-predefined">
565 <para>On Solaris, <command>g++</command> (but not <command>gcc</command>)
566 always defines the preprocessor macro
567 <constant>_XOPEN_SOURCE</constant>. On GNU/Linux, the same happens
568 with <constant>_GNU_SOURCE</constant>. (This is not an exhaustive list;
569 other macros and other platforms are also affected.)
571 <para>These macros are typically used in C library headers, guarding new
572 versions of functions from their older versions. The C++98 standard
573 library includes the C standard library, but it requires the C90
574 version, which for backwards-compatibility reasons is often not the
575 default for many vendors.
577 <para>More to the point, the C++ standard requires behavior which is only
578 available on certain platforms after certain symbols are defined.
579 Usually the issue involves I/O-related typedefs. In order to
580 ensure correctness, the compiler simply predefines those symbols.
582 <para>Note that it's not enough to <literal>#define</literal> them only when the library is
583 being built (during installation). Since we don't have an 'export'
584 keyword, much of the library exists as headers, which means that
585 the symbols must also be defined as your programs are parsed and
588 <para>To see which symbols are defined, look for
589 <varname>CPLUSPLUS_CPP_SPEC</varname> in
590 the gcc config headers for your target (and try changing them to
591 see what happens when building complicated code). You can also run
592 <command>g++ -E -dM - < /dev/null"</command> to display
593 a list of predefined macros for any particular installation.
595 <para>This has been discussed on the mailing lists
596 <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>.
598 <para>This method is something of a wart. We'd like to find a cleaner
599 solution, but nobody yet has contributed the time.
605 <qandaentry xml:id="faq.darwin_ctype">
606 <question xml:id="q-darwin_ctype">
608 Mac OS X <filename class="headerfile">ctype.h</filename> is broken! How can I fix it?
611 <answer xml:id="a-darwin_ctype">
613 <para>This answer is old and probably no longer be relevant.</para>
616 This was a long-standing bug in the OS X support. Fortunately, the
617 <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/ml/gcc/2002-03/msg00817.html">patch</link>
618 was quite simple, and well-known.
624 <qandaentry xml:id="faq.threads_i386">
625 <question xml:id="q-threads_i386">
627 Threading is broken on i386?
630 <answer xml:id="a-threads_i386">
632 <para>This answer is old and probably no longer be relevant.</para>
634 <para>Support for atomic integer operations was broken on i386
635 platforms. The assembly code accidentally used opcodes that are
636 only available on the i486 and later. So if you configured GCC
637 to target, for example, i386-linux, but actually used the programs
638 on an i686, then you would encounter no problems. Only when
639 actually running the code on a i386 will the problem appear.
641 <para>This is fixed in 3.2.2.
647 <qandaentry xml:id="faq.atomic_mips">
648 <question xml:id="q-atomic_mips">
650 MIPS atomic operations
653 <answer xml:id="a-atomic_mips">
655 <para>This answer is old and probably no longer be relevant.</para>
658 The atomic locking routines for MIPS targets requires MIPS II
659 and later. A patch went in just after the 3.3 release to
660 make mips* use the generic implementation instead. You can also
661 configure for mipsel-elf as a workaround.
664 The mips*-*-linux* port continues to use the MIPS II routines, and more
665 work in this area is expected.
670 <qandaentry xml:id="faq.linux_glibc">
671 <question xml:id="q-linux_glibc">
673 Recent GNU/Linux glibc required?
676 <answer xml:id="a-linux_glibc">
677 <para>When running on GNU/Linux, libstdc++ 3.2.1 (shared library version
678 5.0.1) and later uses localization and formatting code from the system
679 C library (glibc) version 2.2.5 which contains necessary bugfixes.
680 All GNU/Linux distros make more recent versions available now.
681 libstdc++ 4.6.0 and later require glibc 2.3 or later for this
682 localization and formatting code.
684 <para>The guideline is simple: the more recent the C++ library, the
685 more recent the C library. (This is also documented in the main
686 GCC installation instructions.)
692 <qandaentry xml:id="faq.freebsd_wchar">
693 <question xml:id="q-freebsd_wchar">
695 Can't use wchar_t/wstring on FreeBSD
698 <answer xml:id="a-freebsd_wchar">
700 <para>This answer is old and probably no longer be relevant.</para>
703 Older versions of FreeBSD's C library do not have sufficient
704 support for wide character functions, and as a result the
705 libstdc++ configury decides that <type>wchar_t</type> support should be
706 disabled. In addition, the libstdc++ platform checks that
707 enabled <type>wchar_t</type> were quite strict, and not granular
708 enough to detect when the minimal support to
709 enable <type>wchar_t</type> and C++ library structures
710 like <classname>wstring</classname> were present. This impacted Solaris,
711 Darwin, and BSD variants, and is fixed in libstdc++ versions post 4.1.0.
722 <qandadiv xml:id="faq.known_bugs" xreflabel="Known Bugs">
725 <qandaentry xml:id="faq.what_works">
726 <question xml:id="q-what_works">
731 <answer xml:id="a-what_works">
733 Short answer: Pretty much everything <emphasis>works</emphasis>
734 except for some corner cases. Support for localization
735 in <classname>locale</classname> may be incomplete on some non-GNU
736 platforms. Also dependent on the underlying platform is support
737 for <type>wchar_t</type> and <type>long
738 long</type> specializations, and details of thread support.
741 Long answer: See the implementation status pages for
742 <link linkend="status.iso.1998">C++98</link>,
743 <link linkend="status.iso.tr1">TR1</link>, and
744 <link linkend="status.iso.2011">C++11</link>.
745 <link linkend="status.iso.2014">C++14</link>.
750 <qandaentry xml:id="faq.standard_bugs">
751 <question xml:id="q-standard_bugs">
753 Bugs in the ISO C++ language or library specification
756 <answer xml:id="a-standard_bugs">
758 Unfortunately, there are some.
761 For those people who are not part of the ISO Library Group
762 (i.e., nearly all of us needing to read this page in the first
763 place), a public list of the library defects is occasionally
764 published on <link xmlns:xlink="http://www.w3.org/1999/xlink"
765 xlink:href="http://www.open-std.org/jtc1/sc22/wg21/">the WG21
767 Many of these issues have resulted in code changes in libstdc++.
770 If you think you've discovered a new bug that is not listed,
771 please post a message describing your problem to the author of
772 the library issues list.
777 <qandaentry xml:id="faq.compiler_bugs">
778 <question xml:id="q-compiler_bugs">
780 Bugs in the compiler (gcc/g++) and not libstdc++
783 <answer xml:id="a-compiler_bugs">
785 On occasion, the compiler is wrong. Please be advised that this
786 happens much less often than one would think, and avoid jumping to
790 First, examine the ISO C++ standard. Second, try another compiler
791 or an older version of the GNU compilers. Third, you can find more
792 information on the libstdc++ and the GCC mailing lists: search
793 these lists with terms describing your issue.
796 Before reporting a bug, please examine the
797 <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/bugs/">bugs database</link> with the
798 category set to <quote>g++</quote>.
805 <!-- Known Non-Bugs -->
806 <qandadiv xml:id="faq.known_non-bugs" xreflabel="Known Non-Bugs">
809 <qandaentry xml:id="faq.stream_reopening_fails">
810 <question xml:id="q-stream_reopening_fails">
812 Reopening a stream fails
815 <answer xml:id="a-stream_reopening_fails">
817 One of the most-reported non-bug reports. Executing a sequence like:
821 #include <fstream>
823 std::fstream fs("a_file");
825 // . do things with fs...
828 fs.open("a_new_file");
832 All operations on the re-opened <varname>fs</varname> will fail, or at
833 least act very strangely. Yes, they often will, especially if
834 <varname>fs</varname> reached the EOF state on the previous file. The
835 reason is that the state flags are <emphasis>not</emphasis> cleared
836 on a successful call to open(). The standard unfortunately did
837 not specify behavior in this case, and to everybody's great sorrow,
838 the <link linkend="manual.intro.status.bugs">proposed LWG resolution in
839 DR #22</link> is to leave the flags unchanged. You must insert a call
840 to <function>fs.clear()</function> between the calls to close() and open(),
841 and then everything will work like we all expect it to work.
842 <emphasis>Update:</emphasis> for GCC 4.0 we implemented the resolution
843 of <link linkend="manual.intro.status.bugs">DR #409</link> and open()
844 now calls <function>clear()</function> on success!
849 <qandaentry xml:id="faq.wefcxx_verbose">
850 <question xml:id="q-wefcxx_verbose">
852 -Weffc++ complains too much
855 <answer xml:id="a-wefcxx_verbose">
857 Many warnings are emitted when <option>-Weffc++</option> is used. Making
858 libstdc++ <option>-Weffc++</option>-clean is not a goal of the project,
859 for a few reasons. Mainly, that option tries to enforce
860 object-oriented programming, while the Standard Library isn't
861 necessarily trying to be OO.
864 We do, however, try to have libstdc++ sources as clean as possible. If
865 you see some simple changes that pacify <option>-Weffc++</option>
866 without other drawbacks, send us a patch.
871 <qandaentry xml:id="faq.ambiguous_overloads">
872 <question xml:id="q-ambiguous_overloads">
874 Ambiguous overloads after including an old-style header
877 <answer xml:id="a-ambiguous_overloads">
879 Another problem is the <literal>rel_ops</literal> namespace and the template
880 comparison operator functions contained therein. If they become
881 visible in the same namespace as other comparison functions
882 (e.g., <quote>using</quote> them and the <iterator> header),
883 then you will suddenly be faced with huge numbers of ambiguity
884 errors. This was discussed on the -v3 list; Nathan Myers
885 <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/ml/libstdc++/2001-01/msg00247.html">sums
886 things up here</link>. The collisions with vector/string iterator
887 types have been fixed for 3.1.
892 <qandaentry xml:id="faq.v2_headers">
893 <question xml:id="q-v2_headers">
895 The g++-3 headers are <emphasis>not ours</emphasis>
898 <answer xml:id="a-v2_headers">
900 If you are using headers in
901 <filename class="directory">${prefix}/include/g++-3</filename>, or if
902 the installed library's name looks like
903 <filename class="libraryfile">libstdc++-2.10.a</filename> or
904 <filename class="libraryfile">libstdc++-libc6-2.10.so</filename>, then
905 you are using the old libstdc++-v2 library, which is non-standard and
906 unmaintained. Do not report problems with -v2 to the -v3
910 For GCC versions 3.0 and 3.1 the libstdc++ header files are installed in
911 <filename class="directory">${prefix}/include/g++-v3</filename>
912 (see the 'v'?). Starting with version 3.2 the headers are installed in
913 <filename class="directory">${prefix}/include/c++/${version}</filename>
914 as this prevents headers from previous versions being found by mistake.
920 <qandaentry xml:id="faq.boost_concept_checks">
921 <question xml:id="q-boost_concept_checks">
923 Errors about <emphasis>*Concept</emphasis> and
924 <emphasis>constraints</emphasis> in the STL
927 <answer xml:id="a-boost_concept_checks">
929 If you see compilation errors containing messages about
930 <errortext>foo Concept</errortext> and something to do with a
931 <errortext>constraints</errortext> member function, then most
932 likely you have violated one of the requirements for types used
933 during instantiation of template containers and functions. For
934 example, EqualityComparableConcept appears if your types must be
935 comparable with == and you have not provided this capability (a
936 typo, or wrong visibility, or you just plain forgot, etc).
939 More information, including how to optionally enable/disable the
940 checks, is available in the
941 <link linkend="std.diagnostics.concept_checking">Diagnostics</link>.
942 chapter of the manual.
947 <qandaentry xml:id="faq.dlopen_crash">
948 <question xml:id="q-dlopen_crash">
950 Program crashes when using library code in a
951 dynamically-loaded library
954 <answer xml:id="a-dlopen_crash">
956 If you are using the C++ library across dynamically-loaded
957 objects, make certain that you are passing the correct options
958 when compiling and linking:
961 <literallayout class="normal">
962 Compile your library components:
963 <command>g++ -fPIC -c a.cc</command>
964 <command>g++ -fPIC -c b.cc</command>
966 <command>g++ -fPIC -c z.cc</command>
969 <command>g++ -fPIC -shared -rdynamic -o libfoo.so a.o b.o ... z.o</command>
972 <command>g++ -fPIC -rdynamic -o foo ... -L. -lfoo -ldl</command>
977 <qandaentry xml:id="faq.memory_leaks">
978 <question xml:id="q-memory_leaks">
980 <quote>Memory leaks</quote> in containers
983 <answer xml:id="a-memory_leaks">
985 A few people have reported that the standard containers appear
986 to leak memory when tested with memory checkers such as
987 <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://valgrind.org/"><command>valgrind</command></link>.
988 Under some configurations the library's allocators keep free memory in a
989 pool for later reuse, rather than returning it to the OS. Although
990 this memory is always reachable by the library and is never
991 lost, memory debugging tools can report it as a leak. If you
992 want to test the library for memory leaks please read
993 <link linkend="debug.memory">Tips for memory leak hunting</link>
999 <qandaentry xml:id="faq.list_size_on">
1000 <question xml:id="q-list_size_on">
1002 list::size() is O(n)!
1005 <answer xml:id="a-list_size_on">
1008 the <link linkend="std.containers">Containers</link>
1014 <qandaentry xml:id="faq.easy_to_fix">
1015 <question xml:id="q-easy_to_fix">
1017 Aw, that's easy to fix!
1020 <answer xml:id="a-easy_to_fix">
1022 If you have found a bug in the library and you think you have
1023 a working fix, then send it in! The main GCC site has a page
1024 on <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/contribute.html">submitting
1025 patches</link> that covers the procedure, but for libstdc++ you
1026 should also send the patch to our mailing list in addition to
1027 the GCC patches mailing list. The libstdc++
1028 <link linkend="appendix.contrib">contributors' page</link>
1029 also talks about how to submit patches.
1032 In addition to the description, the patch, and the ChangeLog
1033 entry, it is a Good Thing if you can additionally create a small
1034 test program to test for the presence of the bug that your patch
1035 fixes. Bugs have a way of being reintroduced; if an old bug
1036 creeps back in, it will be caught immediately by the testsuite -
1037 but only if such a test exists.
1045 <!-- Miscellaneous -->
1046 <qandadiv xml:id="faq.misc" xreflabel="Miscellaneous">
1049 <qandaentry xml:id="faq.iterator_as_pod">
1050 <question xml:id="faq.iterator_as_pod_q">
1052 string::iterator is not char*; vector<T>::iterator is not T*
1055 <answer xml:id="faq.iterator_as_pod_a">
1057 If you have code that depends on container<T> iterators
1058 being implemented as pointer-to-T, your code is broken. It's
1059 considered a feature, not a bug, that libstdc++ points this out.
1062 While there are arguments for iterators to be implemented in
1063 that manner, A) they aren't very good ones in the long term,
1064 and B) they were never guaranteed by the Standard anyway. The
1065 type-safety achieved by making iterators a real class rather
1066 than a typedef for <type>T*</type> outweighs nearly all opposing
1070 Code which does assume that a vector iterator <varname>i</varname>
1071 is a pointer can often be fixed by changing <varname>i</varname> in
1072 certain expressions to <varname>&*i</varname>. Future revisions
1073 of the Standard are expected to bless this usage for
1074 vector<> (but not for basic_string<>).
1079 <qandaentry xml:id="faq.what_is_next">
1080 <question xml:id="q-what_is_next">
1082 What's next after libstdc++?
1085 <answer xml:id="a-what_is_next">
1087 Hopefully, not much. The goal of libstdc++ is to produce a
1088 fully-compliant, fully-portable Standard Library. After that,
1089 we're mostly done: there won't <emphasis>be</emphasis> any
1090 more compliance work to do.
1093 There is an effort underway to add significant extensions to
1094 the standard library specification. The latest version of
1095 this effort is described in
1096 <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1836.pdf">
1097 The C++ Library Technical Report 1</link>.
1102 <qandaentry xml:id="faq.sgi_stl">
1103 <question xml:id="q-sgi_stl">
1105 What about the STL from SGI?
1108 <answer xml:id="a-sgi_stl">
1110 The <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.sgi.com/tech/stl/">STL from SGI</link>,
1111 version 3.3, was the final merge of the STL codebase. The
1112 code in libstdc++ contains many fixes and changes, and
1113 the SGI code is no longer under active
1114 development. We expect that no future merges will take place.
1117 In particular, <classname>string</classname> is not from SGI and makes no
1118 use of their "rope" class (which is included as an
1119 optional extension), nor is <classname>valarray</classname> and some others.
1120 Classes like <classname>vector<></classname> are, but have been
1121 extensively modified.
1124 More information on the evolution of libstdc++ can be found at the
1125 <link linkend="appendix.porting.api">API
1127 and <link linkend="manual.appendix.porting.backwards">backwards
1128 compatibility</link> documentation.
1131 The <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.sgi.com/tech/stl/FAQ.html">FAQ</link>
1132 for SGI's STL is still recommended reading.
1137 <qandaentry xml:id="faq.extensions_and_backwards_compat">
1138 <question xml:id="q-extensions_and_backwards_compat">
1140 Extensions and Backward Compatibility
1143 <answer xml:id="a-extensions_and_backwards_compat">
1145 See the <link linkend="manual.appendix.porting.backwards">link</link> on backwards compatibility and <link linkend="appendix.porting.api">link</link> on evolution.
1150 <qandaentry xml:id="faq.tr1_support">
1151 <question xml:id="q-tr1_support">
1153 Does libstdc++ support TR1?
1156 <answer xml:id="a-tr1_support">
1161 The C++ Standard Library Technical Report adds many new features to
1162 the library. The latest version of this effort is described in
1163 <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1836.pdf">
1164 Technical Report 1</link>.
1167 The implementation status of TR1 in libstdc++ can be tracked <link linkend="status.iso.tr1">on the TR1 status
1173 <qandaentry xml:id="faq.get_iso_cxx">
1174 <question xml:id="q-get_iso_cxx">
1175 <para>How do I get a copy of the ISO C++ Standard?
1178 <answer xml:id="a-get_iso_cxx">
1180 Copies of the full ISO 14882 standard are available on line via
1181 the ISO mirror site for committee members. Non-members, or those
1182 who have not paid for the privilege of sitting on the committee
1183 and sustained their two-meeting commitment for voting rights, may
1184 get a copy of the standard from their respective national
1185 standards organization. In the USA, this national standards
1186 organization is ANSI and their website is
1187 right <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.ansi.org">here</link>. (And if
1188 you've already registered with them, clicking this link will take
1189 you to directly to the place where you can
1190 <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>.
1193 Who is your country's member body? Visit the
1194 <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.iso.ch/">ISO homepage</link> and find out!
1197 The 2003 version of the standard (the 1998 version plus TC1) is
1198 available in print, ISBN 0-470-84674-7.
1203 <qandaentry xml:id="faq.what_is_abi">
1204 <question xml:id="q-what_is_abi">
1206 What's an ABI and why is it so messy?
1209 <answer xml:id="a-what_is_abi">
1211 <acronym>ABI</acronym> stands for <quote>Application Binary
1212 Interface</quote>. Conventionally, it refers to a great
1213 mass of details about how arguments are arranged on the call
1214 stack and/or in registers, and how various types are arranged
1215 and padded in structs. A single CPU design may suffer
1216 multiple ABIs designed by different development tool vendors
1217 who made different choices, or even by the same vendor for
1218 different target applications or compiler versions. In ideal
1219 circumstances the CPU designer presents one ABI and all the
1220 OSes and compilers use it. In practice every ABI omits
1221 details that compiler implementers (consciously or
1222 accidentally) must choose for themselves.
1225 That ABI definition suffices for compilers to generate code so a
1226 program can interact safely with an OS and its lowest-level libraries.
1227 Users usually want an ABI to encompass more detail, allowing libraries
1228 built with different compilers (or different releases of the same
1229 compiler!) to be linked together. For C++, this includes many more
1230 details than for C, and most CPU designers (for good reasons elaborated
1231 below) have not stepped up to publish C++ ABIs. Such an ABI has been
1232 defined for the Itanium architecture (see
1233 <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.codesourcery.com/cxx-abi/">C++
1234 ABI for Itanium</link>) and that is used by G++ and other compilers
1235 as the de facto standard ABI on many common architectures (including x86).
1236 G++ can also use the ARM architecture's EABI, for embedded
1237 systems relying only on a <quote>free-standing implementation</quote> that
1238 doesn't include (much of) the standard library, and the GNU EABI for
1239 hosted implementations on ARM. Those ABIs cover low-level details
1240 such as virtual function implementation, struct inheritance layout,
1241 name mangling, and exception handling.
1244 A useful C++ ABI must also incorporate many details of the standard
1245 library implementation. For a C ABI, the layouts of a few structs
1246 (such as <type>FILE</type>, <type>stat</type>, <type>jmpbuf</type>,
1247 and the like) and a few macros suffice.
1248 For C++, the details include the complete set of names of functions
1249 and types used, the offsets of class members and virtual functions,
1250 and the actual definitions of all inlines. C++ exposes many more
1251 library details to the caller than C does. It makes defining
1252 a complete ABI a much bigger undertaking, and requires not just
1253 documenting library implementation details, but carefully designing
1254 those details so that future bug fixes and optimizations don't
1255 force breaking the ABI.
1258 There are ways to help isolate library implementation details from the
1259 ABI, but they trade off against speed. Library details used in inner
1260 loops (e.g., <function>getchar</function>) must be exposed and frozen for
1261 all time, but many others may reasonably be kept hidden from user code,
1262 so they may later be changed. Deciding which, and implementing
1263 the decisions, must happen before you can reasonably document a
1264 candidate C++ ABI that encompasses the standard library.
1269 <qandaentry xml:id="faq.size_equals_capacity">
1270 <question xml:id="q-size_equals_capacity">
1272 How do I make std::vector<T>::capacity() == std::vector<T>::size?
1275 <answer xml:id="a-size_equals_capacity">
1277 The standard idiom for deallocating a <classname>vector<T></classname>'s
1278 unused memory is to create a temporary copy of the vector and swap their
1279 contents, e.g. for <classname>vector<T> v</classname>
1281 <literallayout class="normal">
1282 std::vector<T>(v).swap(v);
1285 The copy will take O(n) time and the swap is constant time.
1288 See <link linkend="strings.string.shrink">Shrink-to-fit
1289 strings</link> for a similar solution for strings.
1297 <!-- FAQ ends here -->