xref: /netbsd-src/external/gpl3/gcc.old/dist/libstdc++-v3/doc/xml/faq.xml (revision 946379e7b37692fc43f68eb0d1c10daa0a7f3b6c)
1<book xmlns="http://docbook.org/ns/docbook" version="5.0">
2
3<article xml:id="faq" xreflabel="Frequently Asked Questions">
4<?dbhtml filename="faq.html"?>
5
6<info><title>Frequently Asked Questions</title>
7
8  <copyright>
9    <year>
10      2008, 2010
11    </year>
12    <holder>
13      <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.fsf.org">FSF</link>
14    </holder>
15  </copyright>
16</info>
17
18<!-- FAQ starts here -->
19<qandaset>
20
21<!-- General Information -->
22<qandadiv xml:id="faq.info" xreflabel="General Information">
23
24
25<qandaentry xml:id="faq.what">
26  <question xml:id="faq.what.q">
27    <para>
28      What is libstdc++?
29    </para>
30  </question>
31  <answer xml:id="faq.what.a">
32    <para>
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>.
40    </para>
41  </answer>
42</qandaentry>
43
44<qandaentry xml:id="faq.why">
45  <question xml:id="q-why">
46    <para>
47      Why should I use libstdc++?
48    </para>
49  </question>
50  <answer xml:id="a-why">
51    <para>
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
57    that use them.
58    </para>
59    <para>
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
68    applied to libstdc++.
69    </para>
70    <para>
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&lt;&gt;</classname>, iostreams, and algorithms.)
75    Programmers will no longer need to <quote>roll their own</quote>
76    nor be worried about platform-specific incompatibilities.
77    </para>
78  </answer>
79</qandaentry>
80
81<qandaentry xml:id="faq.who">
82  <question xml:id="q-who">
83    <para>
84      Who's in charge of it?
85    </para>
86  </question>
87  <answer xml:id="a-who">
88    <para>
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
93     the SVN archive.
94    </para>
95    <para>
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!
101    </para>
102  </answer>
103</qandaentry>
104
105<qandaentry xml:id="faq.when">
106  <question xml:id="q-when">
107    <para>
108      When is libstdc++ going to be finished?
109    </para>
110  </question>
111  <answer xml:id="a-when">
112    <para>
113    Nathan Myers gave the best of all possible answers, responding to
114    a Usenet article asking this question: <emphasis>Sooner, if you
115    help.</emphasis>
116    </para>
117  </answer>
118</qandaentry>
119
120<qandaentry xml:id="faq.how">
121  <question xml:id="q-how">
122    <para>
123      How do I contribute to the effort?
124    </para>
125  </question>
126  <answer xml:id="a-how">
127    <para>
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!
136    </para>
137  </answer>
138</qandaentry>
139
140<qandaentry xml:id="faq.whereis_old">
141  <question xml:id="q-whereis_old">
142    <para>
143      What happened to the older libg++? I need that!
144    </para>
145  </question>
146  <answer xml:id="a-whereis_old">
147    <para>
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.
151    </para>
152    <para>
153    More information in the <link linkend="manual.appendix.porting.backwards">backwards compatibility documentation</link>
154    </para>
155  </answer>
156</qandaentry>
157
158<qandaentry xml:id="faq.more_questions">
159  <question xml:id="q-more_questions">
160    <para>
161      What if I have more questions?
162    </para>
163  </question>
164  <answer xml:id="a-more_questions">
165    <para>
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>.
172    </para>
173
174    <para>
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.
178    </para>
179  </answer>
180</qandaentry>
181
182</qandadiv>
183
184<!-- License -->
185<qandadiv xml:id="faq.license" xreflabel="License QA">
186
187
188<qandaentry xml:id="faq.license.what">
189  <question xml:id="q-license.what">
190    <para>
191      What are the license terms for libstdc++?
192    </para>
193  </question>
194  <answer xml:id="a-license.what">
195    <para>
196    See <link linkend="manual.intro.status.license">our license description</link>
197    for these and related questions.
198    </para>
199  </answer>
200</qandaentry>
201
202<qandaentry xml:id="faq.license.any_program">
203  <question xml:id="q-license.any_program">
204    <para>
205      So any program which uses libstdc++ falls under the GPL?
206    </para>
207  </question>
208  <answer xml:id="a-license.any_program">
209    <para>
210     No. The special exception permits use of the library in
211     proprietary applications.
212    </para>
213  </answer>
214</qandaentry>
215
216
217<qandaentry xml:id="faq.license.lgpl">
218  <question xml:id="q-license.lgpl">
219    <para>
220      How is that different from the GNU {Lesser,Library} GPL?
221    </para>
222  </question>
223  <answer xml:id="a-license.lgpl">
224    <para>
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.
232    </para>
233  </answer>
234</qandaentry>
235
236<qandaentry xml:id="faq.license.what_restrictions">
237  <question xml:id="q-license.what_restrictions">
238    <para>
239      I see. So, what restrictions are there on programs that use the library?
240    </para>
241  </question>
242  <answer xml:id="a-license.what_restrictions">
243    <para>
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.
246    </para>
247  </answer>
248</qandaentry>
249
250</qandadiv>
251
252<!-- Installation -->
253<qandadiv xml:id="faq.installation" xreflabel="Installation">
254
255
256<qandaentry xml:id="faq.how_to_install">
257  <question xml:id="q-how_to_install">
258    <para>How do I install libstdc++?
259    </para>
260  </question>
261  <answer xml:id="a-how_to_install">
262    <para>
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.
268    </para>
269    <para>
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.
275    </para>
276  </answer>
277</qandaentry>
278
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?
282    </para>
283  </question>
284  <answer xml:id="a-how_to_get_sources">
285    <para>
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.
290    </para>
291    <para>
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>.
296    </para>
297    <para>
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.
303    </para>
304    <para>
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.
308    </para>
309    <para>
310    For more information
311    see <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/svn.html"><acronym>SVN</acronym>
312    details</link>.
313    </para>
314  </answer>
315</qandaentry>
316
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?
320    </para>
321  </question>
322  <answer xml:id="a-how_to_test">
323    <para>
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.
329    </para>
330    <para>
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!
334    </para>
335  </answer>
336</qandaentry>
337
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?
341    </para>
342  </question>
343  <answer xml:id="a-how_to_set_paths">
344    <para>
345    Depending on your platform and library version, the error message might
346    be similar to one of the following:
347    </para>
348
349    <screen>
350    ./a.out: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory
351
352    /usr/libexec/ld-elf.so.1: Shared object "libstdc++.so.6" not found
353    </screen>
354
355    <para>
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:
365    </para>
366
367    <screen>
368    LD_LIBRARY_PATH=${prefix}/lib:$LD_LIBRARY_PATH
369    export LD_LIBRARY_PATH
370    </screen>
371
372    <para>
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    and SHLIB_PATH for HP-UX.
377    </para>
378    <para>
379    See the man pages for <command>ld</command>, <command>ldd</command>
380    and <command>ldconfig</command> for more information. The dynamic
381    linker has different names on different platforms but the man page
382    is usually called something such as <filename>ld.so/rtld/dld.so</filename>.
383    </para>
384    <para>
385    Using LD_LIBRARY_PATH is not always the best solution, <link linkend="manual.intro.using.linkage.dynamic">Finding Dynamic or Shared
386    Libraries</link> in the manual gives some alternatives.
387    </para>
388  </answer>
389</qandaentry>
390
391<qandaentry xml:id="faq.what_is_libsupcxx">
392  <question xml:id="q-what_is_libsupcxx">
393    <para>
394      What's libsupc++?
395    </para>
396  </question>
397  <answer xml:id="a-what_is_libsupcxx">
398    <para>
399      If the only functions from <filename>libstdc++.a</filename>
400      which you need are language support functions (those listed in
401      <link linkend="std.support">clause 18</link> of the
402      standard, e.g., <function>new</function> and
403      <function>delete</function>), then try linking against
404      <filename>libsupc++.a</filename>, which is a subset of
405      <filename>libstdc++.a</filename>.  (Using <command>gcc</command>
406      instead of <command>g++</command> and explicitly linking in
407      <filename>libsupc++.a</filename> via <literal>-lsupc++</literal>
408      for the final link step will do it).  This library contains only
409      those support routines, one per object file.  But if you are
410      using anything from the rest of the library, such as IOStreams
411      or vectors, then you'll still need pieces from
412      <filename>libstdc++.a</filename>.
413    </para>
414  </answer>
415</qandaentry>
416
417<qandaentry xml:id="faq.size">
418  <question xml:id="q-size">
419    <para>
420      This library is HUGE!
421    </para>
422  </question>
423  <answer xml:id="a-size">
424    <para>
425    Usually the size of libraries on disk isn't noticeable.  When a
426    link editor (or simply <quote>linker</quote>) pulls things from a
427    static archive library, only the necessary object files are copied
428    into your executable, not the entire library.  Unfortunately, even
429    if you only need a single function or variable from an object file,
430    the entire object file is extracted.  (There's nothing unique to C++
431    or libstdc++ about this; it's just common behavior, given here
432    for background reasons.)
433    </para>
434    <para>
435    Some of the object files which make up libstdc++.a are rather large.
436    If you create a statically-linked executable with
437    <literal>-static</literal>, those large object files are suddenly part
438    of your executable.  Historically the best way around this was to
439    only place a very few functions (often only a single one) in each
440    source/object file; then extracting a single function is the same
441    as extracting a single .o file.  For libstdc++ this is only
442    possible to a certain extent; the object files in question contain
443    template classes and template functions, pre-instantiated, and
444    splitting those up causes severe maintenance headaches.
445    </para>
446    <para>
447    On supported platforms, libstdc++ takes advantage of garbage
448    collection in the GNU linker to get a result similar to separating
449    each symbol into a separate source and object files. On these platforms,
450    GNU ld can place each function and variable into its own
451    section in a .o file.  The GNU linker can then perform garbage
452    collection on unused sections; this reduces the situation to only
453    copying needed functions into the executable, as before, but all
454    happens automatically.
455    </para>
456  </answer>
457</qandaentry>
458
459</qandadiv>
460
461
462<!-- Platform-Specific Issues -->
463<qandadiv xml:id="faq.platform-specific" xreflabel="Platform-Specific Issues">
464
465
466<qandaentry xml:id="faq.other_compilers">
467  <question xml:id="q-other_compilers">
468    <para>
469      Can libstdc++ be used with non-GNU compilers?
470    </para>
471  </question>
472  <answer xml:id="a-other_compilers">
473    <para>
474    Perhaps.
475    </para>
476    <para>
477    Since the goal of ISO Standardization is for all C++
478    implementations to be able to share code, libstdc++ should be
479    usable under any ISO-compliant compiler, at least in theory.
480    </para>
481    <para>
482    However, the reality is that libstdc++ is targeted and optimized
483    for GCC/g++. This means that often libstdc++ uses specific,
484    non-standard features of g++ that are not present in older
485    versions of proprietary compilers. It may take as much as a year or two
486    after an official release of GCC that contains these features for
487    proprietary tools to support these constructs.
488    </para>
489    <para>
490    In the near past, specific released versions of libstdc++ have
491    been known to work with versions of the EDG C++ compiler, and
492    vendor-specific proprietary C++ compilers such as the Intel ICC
493    C++ compiler.
494    </para>
495
496  </answer>
497</qandaentry>
498
499<qandaentry xml:id="faq.solaris_long_long">
500  <question xml:id="q-solaris_long_long">
501    <para>
502      No 'long long' type on Solaris?
503    </para>
504  </question>
505  <answer xml:id="a-solaris_long_long">
506    <para>
507    By default we try to support the C99 <type>long long</type> type.
508    This requires that certain functions from your C library be present.
509    </para>
510    <para>
511    Up through release 3.0.2 the platform-specific tests performed by
512    libstdc++ were too general, resulting in a conservative approach
513    to enabling the <type>long long</type> code paths. The most
514    commonly reported platform affected was Solaris.
515    </para>
516    <para>
517    This has been fixed for libstdc++ releases greater than 3.0.3.
518    </para>
519  </answer>
520</qandaentry>
521
522<qandaentry xml:id="faq.predefined">
523  <question xml:id="q-predefined">
524    <para>
525      <constant>_XOPEN_SOURCE</constant> and <constant>_GNU_SOURCE</constant> are always defined?
526    </para>
527  </question>
528  <answer xml:id="a-predefined">
529      <para>On Solaris, g++ (but not gcc) always defines the preprocessor
530         macro <constant>_XOPEN_SOURCE</constant>.  On GNU/Linux, the same happens
531         with <constant>_GNU_SOURCE</constant>.  (This is not an exhaustive list;
532         other macros and other platforms are also affected.)
533      </para>
534      <para>These macros are typically used in C library headers, guarding new
535         versions of functions from their older versions.  The C++ standard
536         library includes the C standard library, but it requires the C90
537         version, which for backwards-compatibility reasons is often not the
538         default for many vendors.
539      </para>
540      <para>More to the point, the C++ standard requires behavior which is only
541         available on certain platforms after certain symbols are defined.
542         Usually the issue involves I/O-related typedefs.  In order to
543         ensure correctness, the compiler simply predefines those symbols.
544      </para>
545      <para>Note that it's not enough to #define them only when the library is
546         being built (during installation).  Since we don't have an 'export'
547         keyword, much of the library exists as headers, which means that
548         the symbols must also be defined as your programs are parsed and
549         compiled.
550      </para>
551      <para>To see which symbols are defined, look for CPLUSPLUS_CPP_SPEC in
552         the gcc config headers for your target (and try changing them to
553         see what happens when building complicated code).  You can also run
554         <command>g++ -E -dM - &lt; /dev/null"</command> to display
555         a list of predefined macros for any particular installation.
556      </para>
557      <para>This has been discussed on the mailing lists
558         <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/cgi-bin/htsearch?method=and&amp;format=builtin-long&amp;sort=score&amp;words=_XOPEN_SOURCE+Solaris">quite a bit</link>.
559      </para>
560      <para>This method is something of a wart.  We'd like to find a cleaner
561         solution, but nobody yet has contributed the time.
562      </para>
563
564  </answer>
565</qandaentry>
566
567<qandaentry xml:id="faq.darwin_ctype">
568  <question xml:id="q-darwin_ctype">
569    <para>
570      Mac OS X <filename class="headerfile">ctype.h</filename> is broken! How can I fix it?
571    </para>
572  </question>
573  <answer xml:id="a-darwin_ctype">
574      <para>This is a long-standing bug in the OS X support.  Fortunately,
575         the patch is quite simple, and well-known.
576         <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/ml/gcc/2002-03/msg00817.html"> Here's a
577         link to the solution</link>.
578      </para>
579
580  </answer>
581</qandaentry>
582
583<qandaentry xml:id="faq.threads_i386">
584  <question xml:id="q-threads_i386">
585    <para>
586      Threading is broken on i386?
587    </para>
588  </question>
589  <answer xml:id="a-threads_i386">
590    <para>
591    </para>
592      <para>Support for atomic integer operations is/was broken on i386
593         platforms.  The assembly code accidentally used opcodes that are
594         only available on the i486 and later.  So if you configured GCC
595         to target, for example, i386-linux, but actually used the programs
596         on an i686, then you would encounter no problems.  Only when
597         actually running the code on a i386 will the problem appear.
598      </para>
599      <para>This is fixed in 3.2.2.
600      </para>
601
602  </answer>
603</qandaentry>
604
605<qandaentry xml:id="faq.atomic_mips">
606  <question xml:id="q-atomic_mips">
607    <para>
608      MIPS atomic operations
609    </para>
610  </question>
611  <answer xml:id="a-atomic_mips">
612    <para>
613    The atomic locking routines for MIPS targets requires MIPS II
614    and later.  A patch went in just after the 3.3 release to
615    make mips* use the generic implementation instead.  You can also
616    configure for mipsel-elf as a workaround.
617    </para>
618    <para>
619    The mips*-*-linux* port continues to use the MIPS II routines, and more
620    work in this area is expected.
621    </para>
622  </answer>
623</qandaentry>
624
625<qandaentry xml:id="faq.linux_glibc">
626  <question xml:id="q-linux_glibc">
627    <para>
628      Recent GNU/Linux glibc required?
629    </para>
630  </question>
631  <answer xml:id="a-linux_glibc">
632      <para>When running on GNU/Linux, libstdc++ 3.2.1 (shared library version
633         5.0.1) and later uses localization and formatting code from the system
634         C library (glibc) version 2.2.5 which contains necessary bugfixes.
635         Most GNU/Linux distros make more recent versions available now.
636         libstdc++ 4.6.0 and later require glibc 2.3 or later for this
637         localization and formatting code.
638      </para>
639      <para>The guideline is simple:  the more recent the C++ library, the
640         more recent the C library.  (This is also documented in the main
641         GCC installation instructions.)
642      </para>
643
644  </answer>
645</qandaentry>
646
647<qandaentry xml:id="faq.freebsd_wchar">
648  <question xml:id="q-freebsd_wchar">
649    <para>
650      Can't use wchar_t/wstring on FreeBSD
651    </para>
652  </question>
653  <answer xml:id="a-freebsd_wchar">
654    <para>
655    Older versions of FreeBSD's C library do not have sufficient
656    support for wide character functions, and as a result the
657    libstdc++ configury decides that wchar_t support should be
658    disabled. In addition, the libstdc++ platform checks that
659    enabled <type>wchar_t</type> were quite strict, and not granular
660    enough to detect when the minimal support to
661    enable <type>wchar_t</type> and C++ library structures
662    like <classname>wstring</classname> were present. This impacted Solaris,
663    Darwin, and BSD variants, and is fixed in libstdc++ versions post 4.1.0.
664    </para>
665    <para>
666    </para>
667  </answer>
668</qandaentry>
669
670</qandadiv>
671
672
673<!-- Known Bugs -->
674<qandadiv xml:id="faq.known_bugs" xreflabel="Known Bugs">
675
676
677<qandaentry xml:id="faq.what_works">
678  <question xml:id="q-what_works">
679    <para>
680      What works already?
681    </para>
682  </question>
683  <answer xml:id="a-what_works">
684    <para>
685    Short answer: Pretty much everything <emphasis>works</emphasis>
686    except for some corner cases.  Support for localization
687    in <classname>locale</classname> may be incomplete on non-GNU
688    platforms. Also dependent on the underlying platform is support
689    for <type>wchar_t</type> and <type>long
690    long</type> specializations, and details of thread support.
691    </para>
692    <para>
693    Long answer: See the implementation status pages for
694    <link linkend="status.iso.1998">C++98</link>,
695    <link linkend="status.iso.tr1">TR1</link>, and
696    <link linkend="status.iso.2011">C++11</link>.
697    </para>
698  </answer>
699</qandaentry>
700
701<qandaentry xml:id="faq.standard_bugs">
702  <question xml:id="q-standard_bugs">
703    <para>
704      Bugs in the ISO C++ language or library specification
705    </para>
706  </question>
707  <answer xml:id="a-standard_bugs">
708    <para>
709    Unfortunately, there are some.
710    </para>
711    <para>
712    For those people who are not part of the ISO Library Group
713    (i.e., nearly all of us needing to read this page in the first
714    place), a public list of the library defects is occasionally
715    published on <link xmlns:xlink="http://www.w3.org/1999/xlink"
716    xlink:href="http://www.open-std.org/jtc1/sc22/wg21/">the WG21
717    website</link>.
718    Some of these issues have resulted in code changes in libstdc++.
719    </para>
720    <para>
721    If you think you've discovered a new bug that is not listed,
722    please post a message describing your problem to the author of
723    the library issues list or the Usenet group comp.lang.c++.moderated.
724    </para>
725  </answer>
726</qandaentry>
727
728<qandaentry xml:id="faq.compiler_bugs">
729  <question xml:id="q-compiler_bugs">
730    <para>
731      Bugs in the compiler (gcc/g++) and not libstdc++
732    </para>
733  </question>
734  <answer xml:id="a-compiler_bugs">
735    <para>
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
738    conclusions.
739    </para>
740    <para>
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.
745    </para>
746    <para>
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>.
750    </para>
751  </answer>
752</qandaentry>
753
754</qandadiv>
755
756<!-- Known Non-Bugs -->
757<qandadiv xml:id="faq.known_non-bugs" xreflabel="Known Non-Bugs">
758
759
760<qandaentry xml:id="faq.stream_reopening_fails">
761  <question xml:id="q-stream_reopening_fails">
762    <para>
763      Reopening a stream fails
764    </para>
765  </question>
766  <answer xml:id="a-stream_reopening_fails">
767    <para>
768    One of the most-reported non-bug reports. Executing a sequence like:
769    </para>
770
771    <literallayout class="normal">
772    #include &lt;fstream&gt;
773    ...
774    std::fstream  fs(<quote>a_file</quote>);
775    // .
776    // . do things with fs...
777    // .
778    fs.close();
779    fs.open(<quote>a_new_file</quote>);
780    </literallayout>
781
782    <para>
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!
796    </para>
797  </answer>
798</qandaentry>
799
800<qandaentry xml:id="faq.wefcxx_verbose">
801  <question xml:id="q-wefcxx_verbose">
802    <para>
803      -Weffc++ complains too much
804    </para>
805  </question>
806  <answer xml:id="a-wefcxx_verbose">
807    <para>
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.
813    </para>
814    <para>
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.
818    </para>
819  </answer>
820</qandaentry>
821
822<qandaentry xml:id="faq.ambiguous_overloads">
823  <question xml:id="q-ambiguous_overloads">
824    <para>
825      Ambiguous overloads after including an old-style header
826    </para>
827  </question>
828  <answer xml:id="a-ambiguous_overloads">
829    <para>
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 &lt;iterator&gt; 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.
839    </para>
840  </answer>
841</qandaentry>
842
843<qandaentry xml:id="faq.v2_headers">
844  <question xml:id="q-v2_headers">
845    <para>
846      The g++-3 headers are <emphasis>not ours</emphasis>
847    </para>
848  </question>
849  <answer xml:id="a-v2_headers">
850      <para>
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
857	mailing list.
858      </para>
859      <para>
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.
865      </para>
866
867  </answer>
868</qandaentry>
869
870<qandaentry xml:id="faq.boost_concept_checks">
871  <question xml:id="q-boost_concept_checks">
872    <para>
873      Errors about <emphasis>*Concept</emphasis> and
874      <emphasis>constraints</emphasis> in the STL
875    </para>
876  </question>
877  <answer xml:id="a-boost_concept_checks">
878    <para>
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).
887    </para>
888    <para>
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.
893    </para>
894  </answer>
895</qandaentry>
896
897<qandaentry xml:id="faq.dlopen_crash">
898  <question xml:id="q-dlopen_crash">
899    <para>
900      Program crashes when using library code in a
901      dynamically-loaded library
902    </para>
903  </question>
904  <answer xml:id="a-dlopen_crash">
905    <para>
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:
909    </para>
910
911    <literallayout class="normal">
912    // compile your library components
913    g++ -fPIC -c a.cc
914    g++ -fPIC -c b.cc
915    ...
916    g++ -fPIC -c z.cc
917
918    // create your library
919    g++ -fPIC -shared -rdynamic -o libfoo.so a.o b.o ... z.o
920
921    // link the executable
922    g++ -fPIC -rdynamic -o foo ... -L. -lfoo -ldl
923    </literallayout>
924  </answer>
925</qandaentry>
926
927<qandaentry xml:id="faq.memory_leaks">
928  <question xml:id="q-memory_leaks">
929    <para>
930      <quote>Memory leaks</quote> in containers
931    </para>
932  </question>
933  <answer xml:id="a-memory_leaks">
934    <para>
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    Under some configurations the library's allocators keep free memory in a
939    pool 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>
944    first.
945    </para>
946  </answer>
947</qandaentry>
948
949<qandaentry xml:id="faq.list_size_on">
950  <question xml:id="q-list_size_on">
951    <para>
952      list::size() is O(n)!
953    </para>
954  </question>
955  <answer xml:id="a-list_size_on">
956    <para>
957    See
958    the <link linkend="std.containers">Containers</link>
959    chapter.
960    </para>
961  </answer>
962</qandaentry>
963
964<qandaentry xml:id="faq.easy_to_fix">
965  <question xml:id="q-easy_to_fix">
966    <para>
967      Aw, that's easy to fix!
968    </para>
969  </question>
970  <answer xml:id="a-easy_to_fix">
971    <para>
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.
980    </para>
981    <para>
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.
988    </para>
989  </answer>
990</qandaentry>
991
992</qandadiv>
993
994
995<!-- Miscellaneous -->
996<qandadiv xml:id="faq.misc" xreflabel="Miscellaneous">
997
998
999<qandaentry xml:id="faq.iterator_as_pod">
1000  <question xml:id="faq.iterator_as_pod_q">
1001    <para>
1002      string::iterator is not char*; vector&lt;T&gt;::iterator is not T*
1003    </para>
1004  </question>
1005  <answer xml:id="faq.iterator_as_pod_a">
1006    <para>
1007    If you have code that depends on container&lt;T&gt; 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.
1010    </para>
1011    <para>
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
1017    arguments.
1018    </para>
1019    <para>
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>&amp;*i</varname>.  Future revisions
1023    of the Standard are expected to bless this usage for
1024    vector&lt;&gt; (but not for basic_string&lt;&gt;).
1025    </para>
1026  </answer>
1027</qandaentry>
1028
1029<qandaentry xml:id="faq.what_is_next">
1030  <question xml:id="q-what_is_next">
1031    <para>
1032      What's next after libstdc++?
1033    </para>
1034  </question>
1035  <answer xml:id="a-what_is_next">
1036      <para>
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.
1041      </para>
1042      <para>
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>.
1048      </para>
1049  </answer>
1050</qandaentry>
1051
1052<qandaentry xml:id="faq.sgi_stl">
1053  <question xml:id="q-sgi_stl">
1054    <para>
1055      What about the STL from SGI?
1056    </para>
1057  </question>
1058  <answer xml:id="a-sgi_stl">
1059    <para>
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.
1065    </para>
1066    <para>
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&lt;&gt;</classname> are, but have been
1071    extensively modified.
1072    </para>
1073    <para>
1074    More information on the evolution of libstdc++ can be found at the
1075    <link linkend="appendix.porting.api">API
1076    evolution</link>
1077    and <link linkend="manual.appendix.porting.backwards">backwards
1078    compatibility</link> documentation.
1079    </para>
1080    <para>
1081    The FAQ for SGI's STL (one jump off of their main page) is
1082    still recommended reading.
1083    </para>
1084  </answer>
1085</qandaentry>
1086
1087<qandaentry xml:id="faq.extensions_and_backwards_compat">
1088  <question xml:id="q-extensions_and_backwards_compat">
1089    <para>
1090      Extensions and Backward Compatibility
1091    </para>
1092  </question>
1093  <answer xml:id="a-extensions_and_backwards_compat">
1094    <para>
1095      See the <link linkend="manual.appendix.porting.backwards">link</link> on backwards compatibility and <link linkend="appendix.porting.api">link</link> on evolution.
1096    </para>
1097  </answer>
1098</qandaentry>
1099
1100<qandaentry xml:id="faq.tr1_support">
1101  <question xml:id="q-tr1_support">
1102    <para>
1103      Does libstdc++ support TR1?
1104    </para>
1105  </question>
1106  <answer xml:id="a-tr1_support">
1107    <para>
1108    Yes.
1109    </para>
1110    <para>
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>.
1115    </para>
1116    <para>
1117    The implementation status of TR1 in libstdc++ can be tracked <link linkend="status.iso.tr1">on the TR1 status
1118    page</link>.
1119    </para>
1120  </answer>
1121</qandaentry>
1122
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?
1126    </para>
1127  </question>
1128  <answer xml:id="a-get_iso_cxx">
1129    <para>
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>.
1141    </para>
1142    <para>
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!
1145    </para>
1146    <para>
1147    The 2003 version of the standard (the 1998 version plus TC1) is
1148    available in print, ISBN 0-470-84674-7.
1149    </para>
1150  </answer>
1151</qandaentry>
1152
1153<qandaentry xml:id="faq.what_is_abi">
1154  <question xml:id="q-what_is_abi">
1155    <para>
1156      What's an ABI and why is it so messy?
1157    </para>
1158  </question>
1159  <answer xml:id="a-what_is_abi">
1160    <para>
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.
1173    </para>
1174    <para>
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.
1187    </para>
1188    <para>
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.
1200    </para>
1201    <para>
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.
1209    </para>
1210  </answer>
1211</qandaentry>
1212
1213<qandaentry xml:id="faq.size_equals_capacity">
1214  <question xml:id="q-size_equals_capacity">
1215    <para>
1216      How do I make std::vector&lt;T&gt;::capacity() == std::vector&lt;T&gt;::size?
1217    </para>
1218  </question>
1219  <answer xml:id="a-size_equals_capacity">
1220    <para>
1221    The standard idiom for deallocating a <classname>vector&lt;T&gt;</classname>'s
1222    unused memory is to create a temporary copy of the vector and swap their
1223    contents, e.g. for <classname>vector&lt;T&gt; v</classname>
1224    </para>
1225    <literallayout class="normal">
1226     std::vector&lt;T&gt;(v).swap(v);
1227    </literallayout>
1228    <para>
1229    The copy will take O(n) time and the swap is constant time.
1230    </para>
1231    <para>
1232    See <link linkend="strings.string.shrink">Shrink-to-fit
1233    strings</link> for a similar solution for strings.
1234    </para>
1235  </answer>
1236</qandaentry>
1237
1238</qandadiv>
1239
1240
1241<!-- FAQ ends here -->
1242</qandaset>
1243
1244</article>
1245
1246</book>
1247