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 clauses
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 the Linux kernel.
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 free software,
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 GNU/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.
365 If you already have an older version of libstdc++ installed then the
366 error might look like one of the following instead:
370 ./a.out: /usr/lib/libstdc++.so
.6: version `GLIBCXX_3.4
.20' not found
371 ./a.out: /usr/lib/libstdc++.so
.6: version `CXXABI_1.3
.8' not found
375 This means the linker found
<filename>/usr/lib/libstdc++.so
.6</filename>
376 but that library belongs to an older version of GCC than was used to
377 compile and link the program
<filename>a.out
</filename> (or some part
378 of it). The program depends on code defined in the newer libstdc++
379 that belongs to the newer version of GCC, so the linker must be told
380 how to find the newer libstdc++ shared library.
384 The simplest way to fix this is
385 to use the
<literal>LD_LIBRARY_PATH
</literal> environment variable,
386 which is a colon-separated list of directories in which the linker
387 will search for shared libraries:
391 LD_LIBRARY_PATH=${prefix}/lib:$LD_LIBRARY_PATH
392 export LD_LIBRARY_PATH
396 Here the shell variable
<command>${prefix}
</command> is assumed to contain
397 the directory prefix where GCC was installed to. The directory containing
398 the library might depend on whether you want the
32-bit or
64-bit copy
399 of the library, so for example would be
400 <filename>${prefix}/lib64
</filename> on some systems.
401 The exact environment variable to use will depend on your
402 platform, e.g. DYLD_LIBRARY_PATH for Darwin,
403 LD_LIBRARY_PATH_32/LD_LIBRARY_PATH_64 for Solaris
32-/
64-bit
404 and SHLIB_PATH for HP-UX.
407 See the man pages for
<command>ld
</command>,
<command>ldd
</command>
408 and
<command>ldconfig
</command> for more information. The dynamic
409 linker has different names on different platforms but the man page
410 is usually called something such as
<filename>ld.so
</filename>,
411 <filename>rtld
</filename> or
<filename>dld.so
</filename>.
414 Using LD_LIBRARY_PATH is not always the best solution,
<link linkend=
"manual.intro.using.linkage.dynamic">Finding Dynamic or Shared
415 Libraries
</link> in the manual gives some alternatives.
420 <qandaentry xml:
id=
"faq.what_is_libsupcxx">
421 <question xml:
id=
"q-what_is_libsupcxx">
426 <answer xml:
id=
"a-what_is_libsupcxx">
428 If the only functions from
<filename>libstdc++.a
</filename>
429 which you need are language support functions (those listed in
430 <link linkend=
"std.support">clause
18</link> of the
431 standard, e.g.,
<function>new
</function> and
432 <function>delete
</function>), then try linking against
433 <filename>libsupc++.a
</filename>, which is a subset of
434 <filename>libstdc++.a
</filename>. (Using
<command>gcc
</command>
435 instead of
<command>g++
</command> and explicitly linking in
436 <filename>libsupc++.a
</filename> via
<literal>-lsupc++
</literal>
437 for the final link step will do it). This library contains only
438 those support routines, one per object file. But if you are
439 using anything from the rest of the library, such as IOStreams
440 or vectors, then you'll still need pieces from
441 <filename>libstdc++.a
</filename>.
446 <qandaentry xml:
id=
"faq.size">
447 <question xml:
id=
"q-size">
449 This library is HUGE!
452 <answer xml:
id=
"a-size">
454 Usually the size of libraries on disk isn't noticeable. When a
455 link editor (or simply
<quote>linker
</quote>) pulls things from a
456 static archive library, only the necessary object files are copied
457 into your executable, not the entire library. Unfortunately, even
458 if you only need a single function or variable from an object file,
459 the entire object file is extracted. (There's nothing unique to C++
460 or libstdc++ about this; it's just common behavior, given here
461 for background reasons.)
464 Some of the object files which make up libstdc++.a are rather large.
465 If you create a statically-linked executable with
466 <literal>-static
</literal>, those large object files are suddenly part
467 of your executable. Historically the best way around this was to
468 only place a very few functions (often only a single one) in each
469 source/object file; then extracting a single function is the same
470 as extracting a single .o file. For libstdc++ this is only
471 possible to a certain extent; the object files in question contain
472 template classes and template functions, pre-instantiated, and
473 splitting those up causes severe maintenance headaches.
476 On supported platforms, libstdc++ takes advantage of garbage
477 collection in the GNU linker to get a result similar to separating
478 each symbol into a separate source and object files. On these platforms,
479 GNU ld can place each function and variable into its own
480 section in a .o file. The GNU linker can then perform garbage
481 collection on unused sections; this reduces the situation to only
482 copying needed functions into the executable, as before, but all
483 happens automatically.
491 <!-- Platform-Specific Issues -->
492 <qandadiv xml:
id=
"faq.platform-specific" xreflabel=
"Platform-Specific Issues">
495 <qandaentry xml:
id=
"faq.other_compilers">
496 <question xml:
id=
"q-other_compilers">
498 Can libstdc++ be used with non-GNU compilers?
501 <answer xml:
id=
"a-other_compilers">
506 Since the goal of ISO Standardization is for all C++
507 implementations to be able to share code, libstdc++ should be
508 usable under any ISO-compliant compiler, at least in theory.
511 However, the reality is that libstdc++ is targeted and optimized
512 for GCC/g++. This means that often libstdc++ uses specific,
513 non-standard features of g++ that are not present in older
514 versions of proprietary compilers. It may take as much as a year or two
515 after an official release of GCC that contains these features for
516 proprietary tools to support these constructs.
519 In the near past, specific released versions of libstdc++ have
520 been known to work with versions of the EDG C++ compiler, and
521 vendor-specific proprietary C++ compilers such as the Intel ICC
528 <qandaentry xml:
id=
"faq.solaris_long_long">
529 <question xml:
id=
"q-solaris_long_long">
531 No 'long long' type on Solaris?
534 <answer xml:
id=
"a-solaris_long_long">
536 By default we try to support the C99
<type>long long
</type> type.
537 This requires that certain functions from your C library be present.
540 Up through release
3.0.2 the platform-specific tests performed by
541 libstdc++ were too general, resulting in a conservative approach
542 to enabling the
<type>long long
</type> code paths. The most
543 commonly reported platform affected was Solaris.
546 This has been fixed for libstdc++ releases greater than
3.0.3.
551 <qandaentry xml:
id=
"faq.predefined">
552 <question xml:
id=
"q-predefined">
554 <constant>_XOPEN_SOURCE
</constant> and
<constant>_GNU_SOURCE
</constant> are always defined?
557 <answer xml:
id=
"a-predefined">
558 <para>On Solaris, g++ (but not gcc) always defines the preprocessor
559 macro
<constant>_XOPEN_SOURCE
</constant>. On GNU/Linux, the same happens
560 with
<constant>_GNU_SOURCE
</constant>. (This is not an exhaustive list;
561 other macros and other platforms are also affected.)
563 <para>These macros are typically used in C library headers, guarding new
564 versions of functions from their older versions. The C++ standard
565 library includes the C standard library, but it requires the C90
566 version, which for backwards-compatibility reasons is often not the
567 default for many vendors.
569 <para>More to the point, the C++ standard requires behavior which is only
570 available on certain platforms after certain symbols are defined.
571 Usually the issue involves I/O-related typedefs. In order to
572 ensure correctness, the compiler simply predefines those symbols.
574 <para>Note that it's not enough to #define them only when the library is
575 being built (during installation). Since we don't have an 'export'
576 keyword, much of the library exists as headers, which means that
577 the symbols must also be defined as your programs are parsed and
580 <para>To see which symbols are defined, look for CPLUSPLUS_CPP_SPEC in
581 the gcc config headers for your target (and try changing them to
582 see what happens when building complicated code). You can also run
583 <command>g++ -E -dM -
< /dev/null
"</command> to display
584 a list of predefined macros for any particular installation.
586 <para>This has been discussed on the mailing lists
587 <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>.
589 <para>This method is something of a wart. We'd like to find a cleaner
590 solution, but nobody yet has contributed the time.
596 <qandaentry xml:id="faq.darwin_ctype
">
597 <question xml:id="q-darwin_ctype
">
599 Mac OS X <filename class="headerfile
">ctype.h</filename> is broken! How can I fix it?
602 <answer xml:id="a-darwin_ctype
">
603 <para>This is a long-standing bug in the OS X support. Fortunately,
604 the patch is quite simple, and well-known.
605 <link xmlns:xlink="http://www.w3.org/
1999/xlink
" xlink:href="http://gcc.gnu.org/ml/gcc/
2002-
03/msg00817.html
"> Here's a
606 link to the solution</link>.
612 <qandaentry xml:id="faq.threads_i386
">
613 <question xml:id="q-threads_i386
">
615 Threading is broken on i386?
618 <answer xml:id="a-threads_i386
">
621 <para>Support for atomic integer operations is/was broken on i386
622 platforms. The assembly code accidentally used opcodes that are
623 only available on the i486 and later. So if you configured GCC
624 to target, for example, i386-linux, but actually used the programs
625 on an i686, then you would encounter no problems. Only when
626 actually running the code on a i386 will the problem appear.
628 <para>This is fixed in 3.2.2.
634 <qandaentry xml:id="faq.atomic_mips
">
635 <question xml:id="q-atomic_mips
">
637 MIPS atomic operations
640 <answer xml:id="a-atomic_mips
">
642 The atomic locking routines for MIPS targets requires MIPS II
643 and later. A patch went in just after the 3.3 release to
644 make mips* use the generic implementation instead. You can also
645 configure for mipsel-elf as a workaround.
648 The mips*-*-linux* port continues to use the MIPS II routines, and more
649 work in this area is expected.
654 <qandaentry xml:id="faq.linux_glibc
">
655 <question xml:id="q-linux_glibc
">
657 Recent GNU/Linux glibc required?
660 <answer xml:id="a-linux_glibc
">
661 <para>When running on GNU/Linux, libstdc++ 3.2.1 (shared library version
662 5.0.1) and later uses localization and formatting code from the system
663 C library (glibc) version 2.2.5 which contains necessary bugfixes.
664 Most GNU/Linux distros make more recent versions available now.
665 libstdc++ 4.6.0 and later require glibc 2.3 or later for this
666 localization and formatting code.
668 <para>The guideline is simple: the more recent the C++ library, the
669 more recent the C library. (This is also documented in the main
670 GCC installation instructions.)
676 <qandaentry xml:id="faq.freebsd_wchar
">
677 <question xml:id="q-freebsd_wchar
">
679 Can't use wchar_t/wstring on FreeBSD
682 <answer xml:id="a-freebsd_wchar
">
684 Older versions of FreeBSD's C library do not have sufficient
685 support for wide character functions, and as a result the
686 libstdc++ configury decides that wchar_t support should be
687 disabled. In addition, the libstdc++ platform checks that
688 enabled <type>wchar_t</type> were quite strict, and not granular
689 enough to detect when the minimal support to
690 enable <type>wchar_t</type> and C++ library structures
691 like <classname>wstring</classname> were present. This impacted Solaris,
692 Darwin, and BSD variants, and is fixed in libstdc++ versions post 4.1.0.
703 <qandadiv xml:id="faq.known_bugs
" xreflabel="Known Bugs
">
706 <qandaentry xml:id="faq.what_works
">
707 <question xml:id="q-what_works
">
712 <answer xml:id="a-what_works
">
714 Short answer: Pretty much everything <emphasis>works</emphasis>
715 except for some corner cases. Support for localization
716 in <classname>locale</classname> may be incomplete on non-GNU
717 platforms. Also dependent on the underlying platform is support
718 for <type>wchar_t</type> and <type>long
719 long</type> specializations, and details of thread support.
722 Long answer: See the implementation status pages for
723 <link linkend="status.iso
.1998">C++98</link>,
724 <link linkend="status.iso.tr1
">TR1</link>, and
725 <link linkend="status.iso
.2011">C++11</link>.
726 <link linkend="status.iso
.2014">C++14</link>.
731 <qandaentry xml:id="faq.standard_bugs
">
732 <question xml:id="q-standard_bugs
">
734 Bugs in the ISO C++ language or library specification
737 <answer xml:id="a-standard_bugs
">
739 Unfortunately, there are some.
742 For those people who are not part of the ISO Library Group
743 (i.e., nearly all of us needing to read this page in the first
744 place), a public list of the library defects is occasionally
745 published on <link xmlns:xlink="http://www.w3.org/
1999/xlink
"
746 xlink:href="http://www.open-std.org/jtc1/sc22/wg21/
">the WG21
748 Some of these issues have resulted in code changes in libstdc++.
751 If you think you've discovered a new bug that is not listed,
752 please post a message describing your problem to the author of
753 the library issues list or the Usenet group comp.lang.c++.moderated.
758 <qandaentry xml:id="faq.compiler_bugs
">
759 <question xml:id="q-compiler_bugs
">
761 Bugs in the compiler (gcc/g++) and not libstdc++
764 <answer xml:id="a-compiler_bugs
">
766 On occasion, the compiler is wrong. Please be advised that this
767 happens much less often than one would think, and avoid jumping to
771 First, examine the ISO C++ standard. Second, try another compiler
772 or an older version of the GNU compilers. Third, you can find more
773 information on the libstdc++ and the GCC mailing lists: search
774 these lists with terms describing your issue.
777 Before reporting a bug, please examine the
778 <link xmlns:xlink="http://www.w3.org/
1999/xlink
" xlink:href="http://gcc.gnu.org/bugs/
">bugs database</link> with the
779 category set to <quote>g++</quote>.
786 <!-- Known Non-Bugs -->
787 <qandadiv xml:id="faq.known_non-bugs
" xreflabel="Known Non-Bugs
">
790 <qandaentry xml:id="faq.stream_reopening_fails
">
791 <question xml:id="q-stream_reopening_fails
">
793 Reopening a stream fails
796 <answer xml:id="a-stream_reopening_fails
">
798 One of the most-reported non-bug reports. Executing a sequence like:
801 <literallayout class="normal
">
802 #include <fstream>
804 std::fstream fs("a_file
");
806 // . do things with fs...
809 fs.open("a_new_file
");
813 All operations on the re-opened <varname>fs</varname> will fail, or at
814 least act very strangely. Yes, they often will, especially if
815 <varname>fs</varname> reached the EOF state on the previous file. The
816 reason is that the state flags are <emphasis>not</emphasis> cleared
817 on a successful call to open(). The standard unfortunately did
818 not specify behavior in this case, and to everybody's great sorrow,
819 the <link linkend="manual.intro.status.bugs
">proposed LWG resolution in
820 DR #22</link> is to leave the flags unchanged. You must insert a call
821 to <function>fs.clear()</function> between the calls to close() and open(),
822 and then everything will work like we all expect it to work.
823 <emphasis>Update:</emphasis> for GCC 4.0 we implemented the resolution
824 of <link linkend="manual.intro.status.bugs
">DR #409</link> and open()
825 now calls <function>clear()</function> on success!
830 <qandaentry xml:id="faq.wefcxx_verbose
">
831 <question xml:id="q-wefcxx_verbose
">
833 -Weffc++ complains too much
836 <answer xml:id="a-wefcxx_verbose
">
838 Many warnings are emitted when <literal>-Weffc++</literal> is used. Making
839 libstdc++ <literal>-Weffc++</literal>-clean is not a goal of the project,
840 for a few reasons. Mainly, that option tries to enforce
841 object-oriented programming, while the Standard Library isn't
842 necessarily trying to be OO.
845 We do, however, try to have libstdc++ sources as clean as possible. If
846 you see some simple changes that pacify <literal>-Weffc++</literal>
847 without other drawbacks, send us a patch.
852 <qandaentry xml:id="faq.ambiguous_overloads
">
853 <question xml:id="q-ambiguous_overloads
">
855 Ambiguous overloads after including an old-style header
858 <answer xml:id="a-ambiguous_overloads
">
860 Another problem is the <literal>rel_ops</literal> namespace and the template
861 comparison operator functions contained therein. If they become
862 visible in the same namespace as other comparison functions
863 (e.g., <quote>using</quote> them and the <iterator> header),
864 then you will suddenly be faced with huge numbers of ambiguity
865 errors. This was discussed on the -v3 list; Nathan Myers
866 <link xmlns:xlink="http://www.w3.org/
1999/xlink
" xlink:href="http://gcc.gnu.org/ml/libstdc++/
2001-
01/msg00247.html
">sums
867 things up here</link>. The collisions with vector/string iterator
868 types have been fixed for 3.1.
873 <qandaentry xml:id="faq.v2_headers
">
874 <question xml:id="q-v2_headers
">
876 The g++-3 headers are <emphasis>not ours</emphasis>
879 <answer xml:id="a-v2_headers
">
881 If you are using headers in
882 <filename>${prefix}/include/g++-3</filename>, or if the installed
883 library's name looks like <filename>libstdc++-2.10.a</filename> or
884 <filename>libstdc++-libc6-2.10.so</filename>, then you are using the
885 old libstdc++-v2 library, which is nonstandard and
886 unmaintained. Do not report problems with -v2 to the -v3
890 For GCC versions 3.0 and 3.1 the libstdc++ header files are
891 installed in <filename>${prefix}/include/g++-v3</filename> (see the
892 'v'?). Starting with version 3.2 the headers are installed in
893 <filename>${prefix}/include/c++/${version}</filename> as this prevents
894 headers from previous versions being found by mistake.
900 <qandaentry xml:id="faq.boost_concept_checks
">
901 <question xml:id="q-boost_concept_checks
">
903 Errors about <emphasis>*Concept</emphasis> and
904 <emphasis>constraints</emphasis> in the STL
907 <answer xml:id="a-boost_concept_checks
">
909 If you see compilation errors containing messages about
910 <errortext>foo Concept </errortext>and something to do with a
911 <errortext>constraints</errortext> member function, then most
912 likely you have violated one of the requirements for types used
913 during instantiation of template containers and functions. For
914 example, EqualityComparableConcept appears if your types must be
915 comparable with == and you have not provided this capability (a
916 typo, or wrong visibility, or you just plain forgot, etc).
919 More information, including how to optionally enable/disable the
920 checks, is available in the
921 <link linkend="std.diagnostics.concept_checking
">Diagnostics</link>.
922 chapter of the manual.
927 <qandaentry xml:id="faq.dlopen_crash
">
928 <question xml:id="q-dlopen_crash
">
930 Program crashes when using library code in a
931 dynamically-loaded library
934 <answer xml:id="a-dlopen_crash
">
936 If you are using the C++ library across dynamically-loaded
937 objects, make certain that you are passing the correct options
938 when compiling and linking:
941 <literallayout class="normal
">
942 // compile your library components
948 // create your library
949 g++ -fPIC -shared -rdynamic -o libfoo.so a.o b.o ... z.o
951 // link the executable
952 g++ -fPIC -rdynamic -o foo ... -L. -lfoo -ldl
957 <qandaentry xml:id="faq.memory_leaks
">
958 <question xml:id="q-memory_leaks
">
960 <quote>Memory leaks</quote> in containers
963 <answer xml:id="a-memory_leaks
">
965 A few people have reported that the standard containers appear
966 to leak memory when tested with memory checkers such as
967 <link xmlns:xlink="http://www.w3.org/
1999/xlink
" xlink:href="http://valgrind.org/
">valgrind</link>.
968 Under some configurations the library's allocators keep free memory in a
969 pool for later reuse, rather than returning it to the OS. Although
970 this memory is always reachable by the library and is never
971 lost, memory debugging tools can report it as a leak. If you
972 want to test the library for memory leaks please read
973 <link linkend="debug.memory
">Tips for memory leak hunting</link>
979 <qandaentry xml:id="faq.list_size_on
">
980 <question xml:id="q-list_size_on
">
982 list::size() is O(n)!
985 <answer xml:id="a-list_size_on
">
988 the <link linkend="std.containers
">Containers</link>
994 <qandaentry xml:id="faq.easy_to_fix
">
995 <question xml:id="q-easy_to_fix
">
997 Aw, that's easy to fix!
1000 <answer xml:id="a-easy_to_fix
">
1002 If you have found a bug in the library and you think you have
1003 a working fix, then send it in! The main GCC site has a page
1004 on <link xmlns:xlink="http://www.w3.org/
1999/xlink
" xlink:href="http://gcc.gnu.org/contribute.html
">submitting
1005 patches</link> that covers the procedure, but for libstdc++ you
1006 should also send the patch to our mailing list in addition to
1007 the GCC patches mailing list. The libstdc++
1008 <link linkend="appendix.contrib
">contributors' page</link>
1009 also talks about how to submit patches.
1012 In addition to the description, the patch, and the ChangeLog
1013 entry, it is a Good Thing if you can additionally create a small
1014 test program to test for the presence of the bug that your patch
1015 fixes. Bugs have a way of being reintroduced; if an old bug
1016 creeps back in, it will be caught immediately by the testsuite -
1017 but only if such a test exists.
1025 <!-- Miscellaneous -->
1026 <qandadiv xml:id="faq.misc
" xreflabel="Miscellaneous
">
1029 <qandaentry xml:id="faq.iterator_as_pod
">
1030 <question xml:id="faq.iterator_as_pod_q
">
1032 string::iterator is not char*; vector<T>::iterator is not T*
1035 <answer xml:id="faq.iterator_as_pod_a
">
1037 If you have code that depends on container<T> iterators
1038 being implemented as pointer-to-T, your code is broken. It's
1039 considered a feature, not a bug, that libstdc++ points this out.
1042 While there are arguments for iterators to be implemented in
1043 that manner, A) they aren't very good ones in the long term,
1044 and B) they were never guaranteed by the Standard anyway. The
1045 type-safety achieved by making iterators a real class rather
1046 than a typedef for <type>T*</type> outweighs nearly all opposing
1050 Code which does assume that a vector iterator <varname>i</varname>
1051 is a pointer can often be fixed by changing <varname>i</varname> in
1052 certain expressions to <varname>&*i</varname>. Future revisions
1053 of the Standard are expected to bless this usage for
1054 vector<> (but not for basic_string<>).
1059 <qandaentry xml:id="faq.what_is_next
">
1060 <question xml:id="q-what_is_next
">
1062 What's next after libstdc++?
1065 <answer xml:id="a-what_is_next
">
1067 Hopefully, not much. The goal of libstdc++ is to produce a
1068 fully-compliant, fully-portable Standard Library. After that,
1069 we're mostly done: there won't <emphasis>be</emphasis> any
1070 more compliance work to do.
1073 There is an effort underway to add significant extensions to
1074 the standard library specification. The latest version of
1075 this effort is described in
1076 <link xmlns:xlink="http://www.w3.org/
1999/xlink
" xlink:href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/
2005/n1836.pdf
">
1077 The C++ Library Technical Report 1</link>.
1082 <qandaentry xml:id="faq.sgi_stl
">
1083 <question xml:id="q-sgi_stl
">
1085 What about the STL from SGI?
1088 <answer xml:id="a-sgi_stl
">
1090 The <link xmlns:xlink="http://www.w3.org/
1999/xlink
" xlink:href="http://www.sgi.com/tech/stl/
">STL from SGI</link>,
1091 version 3.3, was the final merge of the STL codebase. The
1092 code in libstdc++ contains many fixes and changes, and
1093 the SGI code is no longer under active
1094 development. We expect that no future merges will take place.
1097 In particular, <classname>string</classname> is not from SGI and makes no
1098 use of their "rope
" class (which is included as an
1099 optional extension), nor is <classname>valarray</classname> and some others.
1100 Classes like <classname>vector<></classname> are, but have been
1101 extensively modified.
1104 More information on the evolution of libstdc++ can be found at the
1105 <link linkend="appendix.porting.api
">API
1107 and <link linkend="manual.appendix.porting.backwards
">backwards
1108 compatibility</link> documentation.
1111 The FAQ for SGI's STL (one jump off of their main page) is
1112 still recommended reading.
1117 <qandaentry xml:id="faq.extensions_and_backwards_compat
">
1118 <question xml:id="q-extensions_and_backwards_compat
">
1120 Extensions and Backward Compatibility
1123 <answer xml:id="a-extensions_and_backwards_compat
">
1125 See the <link linkend="manual.appendix.porting.backwards
">link</link> on backwards compatibility and <link linkend="appendix.porting.api
">link</link> on evolution.
1130 <qandaentry xml:id="faq.tr1_support
">
1131 <question xml:id="q-tr1_support
">
1133 Does libstdc++ support TR1?
1136 <answer xml:id="a-tr1_support
">
1141 The C++ Standard Library Technical Report adds many new features to
1142 the library. The latest version of this effort is described in
1143 <link xmlns:xlink="http://www.w3.org/
1999/xlink
" xlink:href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/
2005/n1836.pdf
">
1144 Technical Report 1</link>.
1147 The implementation status of TR1 in libstdc++ can be tracked <link linkend="status.iso.tr1
">on the TR1 status
1153 <qandaentry xml:id="faq.get_iso_cxx
">
1154 <question xml:id="q-get_iso_cxx
">
1155 <para>How do I get a copy of the ISO C++ Standard?
1158 <answer xml:id="a-get_iso_cxx
">
1160 Copies of the full ISO 14882 standard are available on line via
1161 the ISO mirror site for committee members. Non-members, or those
1162 who have not paid for the privilege of sitting on the committee
1163 and sustained their two-meeting commitment for voting rights, may
1164 get a copy of the standard from their respective national
1165 standards organization. In the USA, this national standards
1166 organization is ANSI and their website is
1167 right <link xmlns:xlink="http://www.w3.org/
1999/xlink
" xlink:href="http://www.ansi.org
">here</link>. (And if
1168 you've already registered with them, clicking this link will take
1169 you to directly to the place where you can
1170 <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>.
1173 Who is your country's member body? Visit the
1174 <link xmlns:xlink="http://www.w3.org/
1999/xlink
" xlink:href="http://www.iso.ch/
">ISO homepage</link> and find out!
1177 The 2003 version of the standard (the 1998 version plus TC1) is
1178 available in print, ISBN 0-470-84674-7.
1183 <qandaentry xml:id="faq.what_is_abi
">
1184 <question xml:id="q-what_is_abi
">
1186 What's an ABI and why is it so messy?
1189 <answer xml:id="a-what_is_abi
">
1191 <acronym>ABI</acronym> stands for <quote>Application Binary
1192 Interface</quote>. Conventionally, it refers to a great
1193 mass of details about how arguments are arranged on the call
1194 stack and/or in registers, and how various types are arranged
1195 and padded in structs. A single CPU design may suffer
1196 multiple ABIs designed by different development tool vendors
1197 who made different choices, or even by the same vendor for
1198 different target applications or compiler versions. In ideal
1199 circumstances the CPU designer presents one ABI and all the
1200 OSes and compilers use it. In practice every ABI omits
1201 details that compiler implementers (consciously or
1202 accidentally) must choose for themselves.
1205 That ABI definition suffices for compilers to generate code so a
1206 program can interact safely with an OS and its lowest-level libraries.
1207 Users usually want an ABI to encompass more detail, allowing libraries
1208 built with different compilers (or different releases of the same
1209 compiler!) to be linked together. For C++, this includes many more
1210 details than for C, and CPU designers (for good reasons elaborated
1211 below) have not stepped up to publish C++ ABIs. The details include
1212 virtual function implementation, struct inheritance layout, name
1213 mangling, and exception handling. Such an ABI has been defined for
1214 GNU C++, and is immediately useful for embedded work relying only on
1215 a <quote>free-standing implementation</quote> that doesn't include (much
1216 of) the standard library. It is a good basis for the work to come.
1219 A useful C++ ABI must also incorporate many details of the standard
1220 library implementation. For a C ABI, the layouts of a few structs
1221 (such as FILE, stat, jmpbuf, and the like) and a few macros suffice.
1222 For C++, the details include the complete set of names of functions
1223 and types used, the offsets of class members and virtual functions,
1224 and the actual definitions of all inlines. C++ exposes many more
1225 library details to the caller than C does. It makes defining
1226 a complete ABI a much bigger undertaking, and requires not just
1227 documenting library implementation details, but carefully designing
1228 those details so that future bug fixes and optimizations don't
1229 force breaking the ABI.
1232 There are ways to help isolate library implementation details from the
1233 ABI, but they trade off against speed. Library details used in
1234 inner loops (e.g., getchar) must be exposed and frozen for all
1235 time, but many others may reasonably be kept hidden from user code,
1236 so they may later be changed. Deciding which, and implementing
1237 the decisions, must happen before you can reasonably document a
1238 candidate C++ ABI that encompasses the standard library.
1243 <qandaentry xml:id="faq.size_equals_capacity
">
1244 <question xml:id="q-size_equals_capacity
">
1246 How do I make std::vector<T>::capacity() == std::vector<T>::size?
1249 <answer xml:id="a-size_equals_capacity
">
1251 The standard idiom for deallocating a <classname>vector<T></classname>'s
1252 unused memory is to create a temporary copy of the vector and swap their
1253 contents, e.g. for <classname>vector<T> v</classname>
1255 <literallayout class="normal
">
1256 std::vector<T>(v).swap(v);
1259 The copy will take O(n) time and the swap is constant time.
1262 See <link linkend="strings.string.shrink
">Shrink-to-fit
1263 strings</link> for a similar solution for strings.
1271 <!-- FAQ ends here -->