OSDN Git Service

2008-02-10 Benjamin Kosnik <bkoz@redhat.com>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / doc / xml / faq.xml
1 <?xml version='1.0'?>
2 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" 
3  "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" 
4 [ ]>
5
6 <book>
7
8 <article id="faq" xreflabel="Frequently Asked Questions">
9 <?dbhtml filename="faq.html"?>
10  
11 <articleinfo>
12   <title>Frequently Asked Questions</title>
13   <copyright>
14     <year>
15       2008
16     </year>
17     <holder>
18       <ulink url="http://fsf.org">FSF</ulink>
19     </holder>
20   </copyright>
21 </articleinfo>
22
23 <!-- FAQ starts here -->
24 <qandaset>
25
26 <!-- General Information -->
27 <qandadiv id="faq.info" xreflabel="General Information">
28 <title>General Information</title>
29
30 <qandaentry id="faq.what">
31   <question id="faq.what.q">
32     <para>
33       What is libstdc++?
34     </para>
35   </question>
36   <answer id="faq.what.a">
37     <para>
38      The GNU Standard C++ Library v3 is an ongoing project to
39      implement the ISO 14882 Standard C++ library as described in
40      chapters 17 through 27 and annex D.  For those who want to see
41      exactly how far the project has come, or just want the latest
42      bleeding-edge code, the up-to-date source is available over
43      anonymous SVN, and can even be browsed over
44      the <ulink url="http://gcc.gnu.org/svn.html">web</ulink>.
45     </para> 
46   </answer>
47 </qandaentry>
48
49 <qandaentry id="faq.why">
50   <question id="q-why">
51     <para>
52       Why should I use libstdc++?
53     </para>
54   </question>
55   <answer id="a-why">
56     <para>
57     The completion of the ISO C++ standardization gave the C++
58     community a powerful set of reuseable tools in the form of the C++
59     Standard Library.  However, all existing C++ implementations are
60     (as the Draft Standard used to say) <quote>incomplet and
61     incorrekt</quote>, and many suffer from limitations of the compilers
62     that use them.
63     </para> 
64     <para>
65     The GNU compiler collection
66     (<command>gcc</command>, <command>g++</command>, etc) is widely
67     considered to be one of the leading compilers in the world.  Its
68     development is overseen by the
69     <ulink url="http://gcc.gnu.org/">GCC team</ulink>.  All of
70     the rapid development and near-legendary
71     <ulink url="http://gcc.gnu.org/buildstat.html">portability</ulink>
72     that are the hallmarks of an open-source project are being
73     applied to libstdc++.
74     </para> 
75     <para>
76     That means that all of the Standard classes and functions will be
77     freely available and fully compliant. (Such as
78     <classname>string</classname>,
79     <classname>vector&lt;&gt;</classname>, iostreams, and algorithms.)
80     Programmers will no longer need to <quote>roll their own</quote>
81     nor be worried about platform-specific incompatibilities.
82     </para> 
83   </answer>
84 </qandaentry>
85
86 <qandaentry id="faq.who">
87   <question id="q-who">
88     <para>
89       Who's in charge of it?
90     </para>
91   </question>
92   <answer id="a-who">
93     <para>
94      The libstdc++ project is contributed to by several developers
95      all over the world, in the same way as GCC or Linux.
96      Benjamin Kosnik, Gabriel Dos Reis, Phil Edwards, Ulrich Drepper,
97      Loren James Rittle, and Paolo Carlini are the lead maintainers of
98      the SVN archive.
99     </para>
100     <para>
101     Development and discussion is held on the libstdc++ mailing
102     list.  Subscribing to the list, or searching the list
103     archives, is open to everyone.  You can read instructions for
104     doing so on the <ulink url="http://gcc.gnu.org/libstdc++/">homepage</ulink>.
105     If you have questions, ideas, code, or are just curious, sign up!
106     </para> 
107   </answer>
108 </qandaentry>
109
110 <qandaentry id="faq.when">
111   <question id="q-when">
112     <para>
113       When is libstdc++ going to be finished?
114     </para>
115   </question>
116   <answer id="a-when">
117     <para>
118     Nathan Myers gave the best of all possible answers, responding to
119     a Usenet article asking this question: <emphasis>Sooner, if you
120     help.</emphasis>
121     </para> 
122   </answer>
123 </qandaentry>
124
125 <qandaentry id="faq.how">
126   <question id="q-how">
127     <para>
128       How do I contribute to the effort?
129     </para>
130   </question>
131   <answer id="a-how">
132     <para>
133     Here is <ulink url="../17_intro/contribute.html">a page devoted to
134     this topic</ulink>. Subscribing to the mailing list (see above, or
135     the homepage) is a very good idea if you have something to
136     contribute, or if you have spare time and want to
137     help. Contributions don't have to be in the form of source code;
138     anybody who is willing to help write documentation, for example,
139     or has found a bug in code that we all thought was working and is
140     willing to provide details, is more than welcome!
141     </para> 
142   </answer>
143 </qandaentry>
144
145 <qandaentry id="faq.whereis_old">
146   <question id="q-whereis_old">
147     <para>
148       What happened to the older libg++? I need that!
149     </para>
150   </question>
151   <answer id="a-whereis_old">
152     <para>
153     The most recent libg++ README states that libg++ is no longer
154     being actively maintained.  It should not be used for new
155     projects, and is only being kicked along to support older code.
156     </para> 
157     <para>
158     More information in the <link linkend="manual.appendix.porting.backwards">backwards compatibility documentation</link>
159     </para>
160   </answer>
161 </qandaentry>
162
163 <qandaentry id="faq.more_questions">
164   <question id="q-more_questions">
165     <para>
166       What if I have more questions?
167     </para>
168   </question>
169   <answer id="a-more_questions">
170     <para>
171     If you have read the README file, and your question remains
172     unanswered, then just ask the mailing list. At present, you do not
173     need to be subscribed to the list to send a message to it.  More
174     information is available on the homepage (including how to browse
175     the list archives); to send a message to the list,
176     use <email>libstdc++@gcc.gnu.org</email>.
177     </para> 
178
179     <para> 
180     If you have a question that you think should be included
181     here, or if you have a question <emphasis>about</emphasis> a question/answer
182     here, please send email to the libstdc++ mailing list, as above.
183     </para> 
184   </answer>
185 </qandaentry>
186
187 </qandadiv>
188
189 <!-- License -->
190 <qandadiv id="faq.license" xreflabel="License QA">
191 <title>License</title>
192
193 <qandaentry id="faq.license.what">
194   <question id="q-license.what">
195     <para>
196       What are the license terms for libstdc++?
197     </para>
198   </question>
199   <answer id="a-license.what">
200     <para>
201     See <link linkend="manual.intro.status.license">our license description</link>
202     for these and related questions.
203     </para> 
204   </answer>
205 </qandaentry>
206
207 <qandaentry id="faq.license.any_program">
208   <question id="q-license.any_program">
209     <para>
210       So any program which uses libstdc++ falls under the GPL?
211     </para>
212   </question>
213   <answer id="a-license.any_program">
214     <para>
215      No. The special exception permits use of the library in
216      proprietary applications.
217     </para> 
218   </answer>
219 </qandaentry>
220
221
222 <qandaentry id="faq.license.lgpl">
223   <question id="q-license.lgpl">
224     <para>
225       How is that different from the GNU {Lesser,Library} GPL?
226     </para>
227   </question>
228   <answer id="a-license.lgpl">
229     <para>
230       The LGPL requires that users be able to replace the LGPL code with a
231      modified version; this is trivial if the library in question is a C
232      shared library.  But there's no way to make that work with C++, where
233      much of the library consists of inline functions and templates, which
234      are expanded inside the code that uses the library.  So to allow people
235      to replace the library code, someone using the library would have to
236      distribute their own source, rendering the LGPL equivalent to the GPL.
237     </para> 
238   </answer>
239 </qandaentry>
240
241 <qandaentry id="faq.license.what_restrictions">
242   <question id="q-license.what_restrictions">
243     <para>
244       I see. So, what restrictions are there on programs that use the library?
245     </para>
246   </question>
247   <answer id="a-license.what_restrictions">
248     <para>
249       None.  We encourage such programs to be released as open source,
250      but we won't punish you or sue you if you choose otherwise.
251     </para> 
252   </answer>
253 </qandaentry>
254
255 </qandadiv>
256
257 <!-- Installation -->
258 <qandadiv id="faq.installation" xreflabel="Installation">
259 <title>Installation</title>
260
261 <qandaentry id="faq.how_to_install">
262   <question id="q-how_to_install">
263     <para>How do I install libstdc++?
264     </para>
265   </question>
266   <answer id="a-how_to_install">
267     <para>
268     Often libstdc++ comes pre-installed as an integral part of many
269     existing Linux and Unix systems, as well as many embedded
270     development tools. It may be necessary to install extra
271     development packages to get the headers, or the documentation, or
272     the source: please consult your vendor for details.
273     </para> 
274     <para> 
275     To build and install from the GNU GCC sources, please consult the 
276     <ulink url="http://gcc.gnu.org/onlinedocs/libstdc++/install.html">install
277     documentation</ulink> for detailed
278     instructions. You may wish to browse those files ahead
279     of time to get a feel for what's required.
280     </para> 
281   </answer>
282 </qandaentry>
283
284 <qandaentry id="faq.how_to_get_sources">
285   <question id="q-how_to_get_sources">
286     <para>How does one get current libstdc++ sources?
287     </para>
288   </question>
289   <answer id="a-how_to_get_sources">
290     <para>
291     Libstdc++ sources for all official releases can be obtained as
292     part of the GCC sources, available from various sites and
293     mirrors. A full <ulink url="http://gcc.gnu.org/mirrors.html">list of 
294     download sites</ulink> is provided on the main GCC site.
295     </para>
296     <para>
297     Current libstdc++ sources can always be checked out of the main
298     GCC source repository using the appropriate version control
299     tool. At this time, that tool
300     is <application>Subversion</application>.
301     </para>
302     <para>
303     <application>Subversion</application>, or <acronym>SVN</acronym>, is
304     one of several revision control packages.  It was selected for GNU
305     projects because it's free (speech), free (beer), and very high
306     quality.  The <ulink url="http://subversion.tigris.org"> Subversion
307     home page</ulink> has a better description.
308     </para>
309     <para>
310     The <quote>anonymous client checkout</quote> feature of SVN is
311     similar to anonymous FTP in that it allows anyone to retrieve
312     the latest libstdc++ sources.
313     </para> 
314     <para>
315     For more information
316     see <ulink url="http://gcc.gnu.org/svn.html"><acronym>SVN</acronym>
317     details</ulink>.
318     </para>
319   </answer>
320 </qandaentry>
321
322 <qandaentry id="faq.how_to_test">
323   <question id="q-how_to_test">
324     <para>How do I know if it works?
325     </para>
326   </question>
327   <answer id="a-how_to_test">
328     <para>
329     Libstdc++ comes with its own validation testsuite, which includes
330     conformance testing, regression testing, ABI testing, and
331     performance testing. Please consult the 
332     <ulink url="http://gcc.gnu.org/install/test.html">testing
333     documentation</ulink> for more details.
334     </para> 
335     <para>
336     If you find bugs in the testsuite programs themselves, or if you
337     think of a new test program that should be added to the suite,
338     <emphasis>please</emphasis> write up your idea and send it to the list!
339     </para>
340   </answer>
341 </qandaentry>
342
343 <qandaentry id="faq.how_to_set_paths">
344   <question id="q-how_to_set_paths">
345     <para>How do I insure that the dynamically linked library will be found?
346     </para>
347   </question>
348   <answer id="a-how_to_set_paths">
349     <para>
350     Depending on your platform and library version, the error message might
351     be similar to one of the following:
352     </para> 
353
354     <screen>
355     ./a.out: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory
356
357     /usr/libexec/ld-elf.so.1: Shared object "libstdc++.so.6" not found
358     </screen>
359
360     <para>
361     This doesn't mean that the shared library isn't installed, only
362     that the dynamic linker can't find it. When a dynamically-linked
363     executable is run the linker finds and loads the required shared
364     libraries by searching a pre-configured list of directories. If
365     the directory where you've installed libstdc++ is not in this list
366     then the libraries won't be found. The simplest way to fix this is
367     to use the <literal>LD_LIBRARY_PATH</literal> environment variable,
368     which is a colon-separated list of directories in which the linker
369     will search for shared libraries:
370     </para> 
371
372     <screen>
373     LD_LIBRARY_PATH=${prefix}/lib:$LD_LIBRARY_PATH
374     export LD_LIBRARY_PATH
375     </screen>
376
377     <para>
378     The exact environment variable to use will depend on your
379     platform, e.g. DYLD_LIBRARY_PATH for Darwin,
380     LD_LIBRARY_PATH_32/LD_LIBRARY_PATH_64 for Solaris 32-/64-bit,
381     LD_LIBRARYN32_PATH/LD_LIBRARY64_PATH for Irix N32/64-bit ABIs and
382     SHLIB_PATH for HP-UX.
383     </para>
384     <para>
385     See the man pages for <command>ld</command>, <command>ldd</command>
386     and <command>ldconfig</command> for more information. The dynamic
387     linker has different names on different platforms but the man page
388     is usually called something such as <filename>ld.so/rtld/dld.so</filename>.
389     </para>
390   </answer>
391 </qandaentry>
392
393 <qandaentry id="faq.what_is_libsupcxx">
394   <question id="q-what_is_libsupcxx">
395     <para>
396       What's libsupc++?
397     </para>
398   </question>
399   <answer id="a-what_is_libsupcxx">
400     <para>
401       If the only functions from <filename>libstdc++.a</filename>
402       which you need are language support functions (those listed in
403       <ulink url="../18_support/howto.html">clause 18</ulink> of the
404       standard, e.g., <function>new</function> and
405       <function>delete</function>), then try linking against
406       <filename>libsupc++.a</filename>, which is a subset of
407       <filename>libstdc++.a</filename>.  (Using <command>gcc</command>
408       instead of <command>g++</command> and explicitly linking in
409       <filename>libsupc++.a</filename> via <literal>-lsupc++</literal>
410       for the final link step will do it).  This library contains only
411       those support routines, one per object file.  But if you are
412       using anything from the rest of the library, such as IOStreams
413       or vectors, then you'll still need pieces from
414       <filename>libstdc++.a</filename>.
415     </para> 
416   </answer>
417 </qandaentry>
418
419 <qandaentry id="faq.size">
420   <question id="q-size">
421     <para>
422       This library is HUGE!
423     </para>
424   </question>
425   <answer id="a-size">
426     <para>
427     Usually the size of libraries on disk isn't noticeable.  When a
428     link editor (or simply <quote>linker</quote>) pulls things from a
429     static archive library, only the necessary object files are copied
430     into your executable, not the entire library.  Unfortunately, even
431     if you only need a single function or variable from an object file,
432     the entire object file is extracted.  (There's nothing unique to C++
433     or libstdc++ about this; it's just common behavior, given here
434     for background reasons.)
435     </para>
436     <para>
437     Some of the object files which make up libstdc++.a are rather large.
438     If you create a statically-linked executable with
439     <literal>-static</literal>, those large object files are suddenly part
440     of your executable.  Historically the best way around this was to
441     only place a very few functions (often only a single one) in each
442     source/object file; then extracting a single function is the same
443     as extracting a single .o file.  For libstdc++ this is only
444     possible to a certain extent; the object files in question contain
445     template classes and template functions, pre-instantiated, and
446     splitting those up causes severe maintenance headaches.
447     </para> 
448     <para>
449     On supported platforms, libstdc++ takes advantage of garbage
450     collection in the GNU linker to get a result similar to separating
451     each symbol into a separate source and object files. On these platforms,
452     GNU ld can place each function and variable into its own
453     section in a .o file.  The GNU linker can then perform garbage
454     collection on unused sections; this reduces the situation to only
455     copying needed functions into the executable, as before, but all
456     happens automatically.
457     </para>
458   </answer>
459 </qandaentry>
460
461 </qandadiv>
462
463
464 <!-- Platorm-Specific Issues -->
465 <qandadiv id="faq.platform-specific" xreflabel="Platform-Specific Issues">
466 <title>Platform-Specific Issues</title>
467
468 <qandaentry id="faq.other_compilers">
469   <question id="q-other_compilers">
470     <para>
471       Can libstdc++ be used with non-GNU compilers?
472     </para>
473   </question>
474   <answer id="a-other_compilers">
475     <para>
476     Perhaps.
477     </para> 
478     <para>
479     Since the goal of ISO Standardization is for all C++
480     implementations to be able to share code, libstdc++ should be
481     usable under any ISO-compliant compiler, at least in theory.
482     </para> 
483     <para>
484     However, the reality is that libstdc++ is targeted and optimized
485     for GCC/g++. This means that often libstdc++ uses specific,
486     non-standard features of g++ that are not present in older
487     versions of proprietary compilers. It may take as much as a year or two
488     after an official release of GCC that contains these features for
489     proprietary tools support these constructs.
490     </para>
491     <para>
492     In the near past, specific released versions of libstdc++ have
493     been known to work with versions of the EDG C++ compiler, and
494     vendor-specific proprietary C++ compilers such as the Intel ICC
495     C++ compiler.
496     </para> 
497
498   </answer>
499 </qandaentry>
500
501 <qandaentry id="faq.solaris_long_long">
502   <question id="q-solaris_long_long">
503     <para>
504       No 'long long' type on Solaris?
505     </para>
506   </question>
507   <answer id="a-solaris_long_long">
508     <para>
509     By default we try to support the C99 <type>long long</type> type.
510     This requires that certain functions from your C library be present.
511     </para> 
512     <para> 
513     Up through release 3.0.2 the platform-specific tests performed by
514     libstdc++ were too general, resulting in a conservative approach
515     to enabling the <type>long long</type> code paths. The most
516     commonly reported platform affected was Solaris.
517     </para> 
518     <para> 
519     This has been fixed for libstdc++ releases greater than 3.0.3.
520     </para> 
521   </answer>
522 </qandaentry>
523
524 <qandaentry id="faq.predefined">
525   <question id="q-predefined">
526     <para>
527       <constant>_XOPEN_SOURCE</constant> and <constant>_GNU_SOURCE</constant> are always defined?
528     </para>
529   </question>
530   <answer id="a-predefined">
531       <para>On Solaris, g++ (but not gcc) always defines the preprocessor
532          macro <constant>_XOPEN_SOURCE</constant>.  On GNU/Linux, the same happens
533          with <constant>_GNU_SOURCE</constant>.  (This is not an exhaustive list;
534          other macros and other platforms are also affected.)
535       </para>
536       <para>These macros are typically used in C library headers, guarding new
537          versions of functions from their older versions.  The C++ standard
538          library includes the C standard library, but it requires the C90
539          version, which for backwards-compatibility reasons is often not the
540          default for many vendors.
541       </para>
542       <para>More to the point, the C++ standard requires behavior which is only
543          available on certain platforms after certain symbols are defined.
544          Usually the issue involves I/O-related typedefs.  In order to
545          ensure correctness, the compiler simply predefines those symbols.
546       </para>
547       <para>Note that it's not enough to #define them only when the library is
548          being built (during installation).  Since we don't have an 'export'
549          keyword, much of the library exists as headers, which means that
550          the symbols must also be defined as your programs are parsed and
551          compiled.
552       </para>
553       <para>To see which symbols are defined, look for CPLUSPLUS_CPP_SPEC in
554          the gcc config headers for your target (and try changing them to
555          see what happens when building complicated code).  You can also run
556          <command>g++ -E -dM - &lt; /dev/null&quot;</command> to display
557          a list of predefined macros for any particular installation.
558       </para>
559       <para>This has been discussed on the mailing lists
560          <ulink url="http://gcc.gnu.org/cgi-bin/htsearch?method=and&amp;format=builtin-long&amp;sort=score&amp;words=_XOPEN_SOURCE+Solaris">quite a bit</ulink>.
561       </para>
562       <para>This method is something of a wart.  We'd like to find a cleaner
563          solution, but nobody yet has contributed the time.
564       </para>
565
566   </answer>
567 </qandaentry>
568
569 <qandaentry id="faq.darwin_ctype">
570   <question id="q-darwin_ctype">
571     <para>
572       Mac OS X <filename class="headerfile">ctype.h</filename> is broken! How can I fix it?
573     </para>
574   </question>
575   <answer id="a-darwin_ctype">
576       <para>This is a long-standing bug in the OS X support.  Fortunately,
577          the patch is quite simple, and well-known.
578          <ulink url="http://gcc.gnu.org/ml/gcc/2002-03/msg00817.html"> Here's a
579          link to the solution</ulink>.
580       </para>
581
582   </answer>
583 </qandaentry>
584
585 <qandaentry id="faq.threads_i386">
586   <question id="q-threads_i386">
587     <para>
588       Threading is broken on i386?
589     </para>
590   </question>
591   <answer id="a-threads_i386">
592     <para>
593     </para> 
594       <para>Support for atomic integer operations is/was broken on i386
595          platforms.  The assembly code accidentally used opcodes that are
596          only available on the i486 and later.  So if you configured GCC
597          to target, for example, i386-linux, but actually used the programs
598          on an i686, then you would encounter no problems.  Only when
599          actually running the code on a i386 will the problem appear.
600       </para>
601       <para>This is fixed in 3.2.2.
602       </para>
603
604   </answer>
605 </qandaentry>
606
607 <qandaentry id="faq.atomic_mips">
608   <question id="q-atomic_mips">
609     <para>
610       MIPS atomic operations
611     </para>
612   </question>
613   <answer id="a-atomic_mips">
614     <para>
615     The atomic locking routines for MIPS targets requires MIPS II
616     and later.  A patch went in just after the 3.3 release to
617     make mips* use the generic implementation instead.  You can also
618     configure for mipsel-elf as a workaround.
619     </para>
620     <para>    
621     The mips*-*-linux* port continues to use the MIPS II routines, and more
622     work in this area is expected.
623     </para> 
624   </answer>
625 </qandaentry>
626
627 <qandaentry id="faq.linux_glibc">
628   <question id="q-linux_glibc">
629     <para>
630       Recent GNU/Linux glibc required?
631     </para>
632   </question>
633   <answer id="a-linux_glibc">
634       <para>When running on GNU/Linux, libstdc++ 3.2.1 (shared library version
635          5.0.1) and later uses localization and formatting code from the system
636          C library (glibc) version 2.2.5.  That version of glibc is over a
637          year old and contains necessary bugfixes.  Many GNU/Linux distros make
638          glibc version 2.3.x available now.
639       </para>
640       <para>The guideline is simple:  the more recent the C++ library, the
641          more recent the C library.  (This is also documented in the main
642          GCC installation instructions.)
643       </para>
644
645   </answer>
646 </qandaentry>
647
648 <qandaentry id="faq.freebsd_wchar">
649   <question id="q-freebsd_wchar">
650     <para>
651       Can't use wchar_t/wstring on FreeBSD
652     </para>
653   </question>
654   <answer id="a-freebsd_wchar">
655     <para>
656     Older versions of FreeBSD's C library do not have sufficient
657     support for wide character functions, and as a result the
658     libstdc++ configury decides that wchar_t support should be
659     disabled. In addition, the libstdc++ platform checks that
660     enabled <type>wchar_t</type> were quite strict, and not granular
661     enough to detect when the minimal support to
662     enable <type>wchar_t</type> and C++ library structures
663     like <classname>wstring</classname> were present. This impacted Solaris,
664     Darwin, and BSD varients, and is fixed in libstdc++ versions post 4.1.0.
665     </para> 
666     <para> 
667     </para> 
668   </answer>
669 </qandaentry>
670
671 </qandadiv>
672
673
674 <!-- Known Bugs -->
675 <qandadiv id="faq.known_bugs" xreflabel="Known Bugs">
676 <title>Known Bugs</title>
677
678 <qandaentry id="faq.what_works">
679   <question id="q-what_works">
680     <para>
681       What works already?
682     </para>
683   </question>
684   <answer id="a-what_works">
685     <para>
686     Short answer: Pretty much everything <emphasis>works</emphasis>
687     except for some corner cases.  Support for localization
688     in <classname>locale</classname> may be incomplete on non-GNU
689     platforms. Also dependant on the underlying platform is support
690     for <type>wchar_t</type> and <type>long
691     long</type> specializations, and details of thread support.
692     </para>
693     <para>    
694     Long answer: See the implementation status pages for 
695     <ulink url="http://gcc.gnu.org/onlinedocs/libstdc++/17_intro/c++1998_status.html">C++98</ulink>,
696     <ulink url="http://gcc.gnu.org/onlinedocs/libstdc++/17_intro/tr1_status.html">TR1</ulink>, and <ulink url="http://gcc.gnu.org/onlinedocs/libstdc++/17_intro/c++0x_status.html">C++0x</ulink>.
697     </para> 
698   </answer>
699 </qandaentry>
700
701 <qandaentry id="faq.standard_bugs">
702   <question id="q-standard_bugs">
703     <para>
704       Bugs in the ISO C++ language or library specification
705     </para>
706   </question>
707   <answer 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 <ulink url="http://anubis.dkuug.dk/jtc1/sc22/wg21/">here</ulink>.
716     Some of these issues have resulted in code changes in libstdc++.
717     </para> 
718     <para>
719     If you think you've discovered a new bug that is not listed,
720     please post a message describing your problem
721     to <email>libstdc++@gcc.gnu.org</email> or the Usenet group
722     comp.lang.c++.moderated.
723     </para>
724   </answer>
725 </qandaentry>
726
727 <qandaentry id="faq.compiler_bugs">
728   <question id="q-compiler_bugs">
729     <para>
730       Bugs in the compiler (gcc/g++) and not libstdc++
731     </para>
732   </question>
733   <answer id="a-compiler_bugs">
734     <para>
735     On occasion, the compiler is wrong. Please be advised that this
736     happens much less often than one would think, and avoid jumping to
737     conclusions.
738     </para>
739     <para>
740     First, examine the ISO C++ standard. Second, try another compiler
741     or an older version of the GNU compilers. Third, you can find more
742     information on the libstdc++ and the GCC mailing lists: search
743     these lists with terms describing your issue.
744     </para> 
745     <para> 
746     Before reporting a bug, please examine the
747     <ulink url="http://gcc.gnu.org/bugs.html">bugs database</ulink> with the
748     category set to <quote>g++</quote>. 
749     </para> 
750   </answer>
751 </qandaentry>
752
753 </qandadiv>
754
755 <!-- Known Non-Bugs -->
756 <qandadiv id="faq.known_non-bugs" xreflabel="Known Non-Bugs">
757 <title>Known Non-Bugs</title>
758
759 <qandaentry id="faq.stream_reopening_fails">
760   <question id="q-stream_reopening_fails">
761     <para>
762       Reopening a stream fails
763     </para>
764   </question>
765   <answer id="a-stream_reopening_fails">
766     <para>
767     One of the most-reported non-bug reports. Executing a sequence like:
768     </para>
769
770     <literallayout>
771     #include &lt;fstream&gt;
772     ...
773     std::fstream  fs(<quote>a_file</quote>);
774     // .
775     // . do things with fs...
776     // .
777     fs.close();
778     fs.open(<quote>a_new_file</quote>);
779     </literallayout>
780     
781     <para>
782     All operations on the re-opened <varname>fs</varname> will fail, or at
783     least act very strangely.  Yes, they often will, especially if
784     <varname>fs</varname> reached the EOF state on the previous file.  The
785     reason is that the state flags are <emphasis>not</emphasis> cleared
786     on a successful call to open().  The standard unfortunately did
787     not specify behavior in this case, and to everybody's great sorrow,
788     the <ulink url="../ext/howto.html#5">proposed LWG resolution in
789       DR #22</ulink> is to leave the flags unchanged.  You must insert a call
790     to <function>fs.clear()</function> between the calls to close() and open(),
791     and then everything will work like we all expect it to work.
792     <emphasis>Update:</emphasis> for GCC 4.0 we implemented the resolution
793     of <ulink url="../ext/howto.html#5">DR #409</ulink> and open() now calls
794     <function>clear()</function> on success!
795     </para> 
796   </answer>
797 </qandaentry>
798
799 <qandaentry id="faq.wefcxx_verbose">
800   <question id="q-wefcxx_verbose">
801     <para>
802       -Weffc++ complains too much
803     </para>
804   </question>
805   <answer id="a-wefcxx_verbose">
806     <para>
807     Many warnings are emitted when <literal>-Weffc++</literal> is used.  Making
808     libstdc++ <literal>-Weffc++</literal>-clean is not a goal of the project,
809     for a few reasons.  Mainly, that option tries to enforce
810     object-oriented programming, while the Standard Library isn't
811     necessarily trying to be OO.
812     </para> 
813     <para>
814     We do, however, try to have libstdc++ sources as clean as possible. If
815     you see some simple changes that pacify <literal>-Weffc++</literal>
816     without other drawbacks, send us a patch.
817     </para>
818   </answer>
819 </qandaentry>
820
821 <qandaentry id="faq.ambiguous_overloads">
822   <question id="q-ambiguous_overloads">
823     <para>
824       Ambiguous overloads after including an old-style header
825     </para>
826   </question>
827   <answer id="a-ambiguous_overloads">
828     <para>
829     Another problem is the <literal>rel_ops</literal> namespace and the template
830     comparison operator functions contained therein.  If they become
831     visible in the same namespace as other comparison functions
832     (e.g., <quote>using</quote> them and the &lt;iterator&gt; header),
833     then you will suddenly be faced with huge numbers of ambiguity
834     errors.  This was discussed on the -v3 list; Nathan Myers
835     <ulink url="http://gcc.gnu.org/ml/libstdc++/2001-01/msg00247.html">sums
836       things up here</ulink>.  The collisions with vector/string iterator
837     types have been fixed for 3.1.
838     </para> 
839   </answer>
840 </qandaentry>
841
842 <qandaentry id="faq.v2_headers">
843   <question id="q-v2_headers">
844     <para>
845       The g++-3 headers are <emphasis>not ours</emphasis>
846     </para>
847   </question>
848   <answer id="a-v2_headers">
849       <para>
850         If you have found an extremely broken header file which is
851         causing problems for you, look carefully before submitting a
852         &quot;high&quot; priority bug report (which you probably
853         shouldn't do anyhow; see the last paragraph of the page
854         describing <ulink url="http://gcc.gnu.org/bugs.html">the GCC
855         bug database</ulink>).
856       </para>
857       <para>
858         If the headers are in <filename>${prefix}/include/g++-3</filename>, or
859         if the installed library's name looks like
860         <filename>libstdc++-2.10.a</filename> or
861         <filename>libstdc++-libc6-2.10.so</filename>, then you are using the
862         old libstdc++-v2 library, which is nonstandard and
863         unmaintained.  Do not report problems with -v2 to the -v3
864         mailing list.
865       </para>
866       <para>
867         For GCC versions 3.0 and 3.1 the libstdc++ header files are
868         installed in <filename>${prefix}/include/g++-v3</filename> (see the
869         'v'?).  Starting with version 3.2 the headers are installed in
870         <filename>${prefix}/include/c++/${version}</filename> as this prevents
871         headers from previous versions being found by mistake.
872       </para>
873
874   </answer>
875 </qandaentry>
876
877 <qandaentry id="faq.boost_concept_checks">
878   <question id="q-boost_concept_checks">
879     <para>
880       Errors about <emphasis>*Concept</emphasis> and
881       <emphasis>constraints</emphasis> in the STL
882     </para>
883   </question>
884   <answer id="a-boost_concept_checks">
885     <para>
886     If you see compilation errors containing messages about
887     <errortext>foo Concept </errortext>and something to do with a
888     <errortext>constraints</errortext> member function, then most
889     likely you have violated one of the requirements for types used
890     during instantiation of template containers and functions.  For
891     example, EqualityComparableConcept appears if your types must be
892     comparable with == and you have not provided this capability (a
893     typo, or wrong visibility, or you just plain forgot, etc).
894     </para>
895     <para>
896     More information, including how to optionally enable/disable the
897     checks, is available
898     <ulink url="../19_diagnostics/howto.html#3">here</ulink>.
899     </para> 
900   </answer>
901 </qandaentry>
902
903 <qandaentry id="faq.dlopen_crash">
904   <question id="q-dlopen_crash">
905     <para>
906       Program crashes when using library code in a
907       dynamically-loaded library
908     </para>
909   </question>
910   <answer id="a-dlopen_crash">
911     <para>
912     If you are using the C++ library across dynamically-loaded
913     objects, make certain that you are passing the correct options
914     when compiling and linking:
915     </para>
916
917     <literallayout>
918     // compile your library components
919     g++ -fPIC -c a.cc
920     g++ -fPIC -c b.cc
921     ...
922     g++ -fPIC -c z.cc
923
924     // create your library
925     g++ -fPIC -shared -rdynamic -o libfoo.so a.o b.o ... z.o
926
927     // link the executable
928     g++ -fPIC -rdynamic -o foo ... -L. -lfoo -ldl
929     </literallayout>
930   </answer>
931 </qandaentry>
932
933 <qandaentry id="faq.memory_leaks">
934   <question id="q-memory_leaks">
935     <para>
936       <quote>Memory leaks</quote> in containers
937     </para>
938   </question>
939   <answer id="a-memory_leaks">
940     <para>
941     A few people have reported that the standard containers appear
942     to leak memory when tested with memory checkers such as
943     <ulink url="http://developer.kde.org/~sewardj/">valgrind</ulink>.
944     The library's default allocators keep free memory in a pool
945     for later reuse, rather than returning it to the OS.  Although
946     this memory is always reachable by the library and is never
947     lost, memory debugging tools can report it as a leak.  If you
948     want to test the library for memory leaks please read
949     <ulink url="../debug.html#mem">Tips for memory leak hunting</ulink>
950     first.
951     </para> 
952   </answer>
953 </qandaentry>
954
955 <qandaentry id="faq.list_size_on">
956   <question id="q-list_size_on">
957     <para>
958       list::size() is O(n)!
959     </para>
960   </question>
961   <answer id="a-list_size_on">
962     <para>
963     See
964     the <ulink url="../23_containers/howto.html#6">Containers</ulink>
965     chapter.
966     </para> 
967   </answer>
968 </qandaentry>
969
970 <qandaentry id="faq.easy_to_fix">
971   <question id="q-easy_to_fix">
972     <para>
973       Aw, that's easy to fix!
974     </para>
975   </question>
976   <answer id="a-easy_to_fix">
977     <para>
978     If you have found a bug in the library and you think you have
979     a working fix, then send it in!  The main GCC site has a page
980     on <ulink url="http://gcc.gnu.org/contribute.html">submitting
981     patches</ulink> that covers the procedure, but for libstdc++ you
982     should also send the patch to our mailing list in addition to
983     the GCC patches mailing list.  The libstdc++
984     <ulink url="../17_intro/contribute.html">contributors' page</ulink>
985     also talks about how to submit patches.
986     </para>
987     <para>
988     In addition to the description, the patch, and the ChangeLog
989     entry, it is a Good Thing if you can additionally create a small
990     test program to test for the presence of the bug that your
991     patch fixes.  Bugs have a way of being reintroduced; if an old
992     bug creeps back in, it will be caught immediately by the
993     <ulink url="#2_4">testsuite</ulink> -- but only if such a test exists.
994     </para> 
995   </answer>
996 </qandaentry>
997
998 </qandadiv>
999
1000
1001 <!-- Miscellaneous -->
1002 <qandadiv id="faq.misc" xreflabel="Miscellaneous">
1003 <title>Miscellaneous</title>
1004
1005 <qandaentry id="faq.iterator_as_pod">
1006   <question id="faq.iterator_as_pod_q">
1007     <para>
1008       string::iterator is not char*; vector&lt;T&gt;::iterator is not T*
1009     </para>
1010   </question>
1011   <answer id="faq.iterator_as_pod_a">
1012     <para>
1013     If you have code that depends on container&lt;T&gt; iterators
1014     being implemented as pointer-to-T, your code is broken. It's
1015     considered a feature, not a bug, that libstdc++ points this out.
1016     </para>
1017     <para>
1018     While there are arguments for iterators to be implemented in
1019     that manner, A) they aren't very good ones in the long term,
1020     and B) they were never guaranteed by the Standard anyway.  The
1021     type-safety achieved by making iterators a real class rather
1022     than a typedef for <type>T*</type> outweighs nearly all opposing
1023     arguments.
1024     </para>
1025     <para>
1026     Code which does assume that a vector iterator <varname>i</varname>
1027     is a pointer can often be fixed by changing <varname>i</varname> in
1028     certain expressions to <varname>&amp;*i</varname>.  Future revisions
1029     of the Standard are expected to bless this usage for
1030     vector&lt;&gt; (but not for basic_string&lt;&gt;).
1031     </para>
1032   </answer>
1033 </qandaentry>
1034
1035 <qandaentry id="faq.what_is_next">
1036   <question id="q-what_is_next">
1037     <para>
1038       What's next after libstdc++?
1039     </para>
1040   </question>
1041   <answer id="a-what_is_next">
1042       <para>
1043         Hopefully, not much.  The goal of libstdc++ is to produce a
1044         fully-compliant, fully-portable Standard Library.  After that,
1045         we're mostly done: there won't <emphasis>be</emphasis> any
1046         more compliance work to do.
1047       </para>
1048       <para>
1049         There is an effort underway to add significant extensions to
1050         the standard library specification.  The latest version of
1051         this effort is described in
1052          <ulink url="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1836.pdf">
1053          The C++ Library Technical Report 1</ulink>.
1054       </para>
1055   </answer>
1056 </qandaentry>
1057
1058 <qandaentry id="faq.sgi_stl">
1059   <question id="q-sgi_stl">
1060     <para>
1061       What about the STL from SGI?
1062     </para>
1063   </question>
1064   <answer id="a-sgi_stl">
1065     <para>
1066       The <ulink url="http://www.sgi.com/tech/stl/">STL from SGI</ulink>,
1067     version 3.3, was the final merge of the STL codebase.  The
1068     code in libstdc++ contains many fixes and changes, and
1069     the SGI code is no longer under active
1070     development.  We expect that no future merges will take place.
1071     </para>
1072     <para>
1073     In particular, <classname>string</classname> is not from SGI and makes no
1074     use of their &quot;rope&quot; class (which is included as an
1075     optional extension), nor is <classname>valarray</classname> and some others.
1076     Classes like <classname>vector&lt;&gt;</classname> are, but have been
1077     extensively modified.
1078     </para>
1079     <para>
1080     More information on the evolution of libstdc++ can be found at the
1081     <link linkend="appendix.porting.api">API
1082     evolution</link>
1083     and <link linkend="manual.appendix.porting.backwards">backwards
1084     compatibility</link> documentation.
1085     </para>
1086     <para>
1087     The FAQ for SGI's STL (one jump off of their main page) is
1088     still recommended reading.
1089     </para> 
1090   </answer>
1091 </qandaentry>
1092
1093 <qandaentry id="faq.extensions_and_backwards_compat">
1094   <question id="q-extensions_and_backwards_compat">
1095     <para>
1096       Extensions and Backward Compatibility
1097     </para>
1098   </question>
1099   <answer id="a-extensions_and_backwards_compat">
1100     <para>
1101       See the <link linkend="manual.appendix.porting.backwards">link</link> on backwards compatiblity and <link linkend="appendix.porting.api">link</link> on evolution.
1102     </para> 
1103   </answer>
1104 </qandaentry>
1105
1106 <qandaentry id="faq.tr1_support">
1107   <question id="q-tr1_support">
1108     <para>
1109       Does libstdc++ support TR1?
1110     </para>
1111   </question>
1112   <answer id="a-tr1_support">
1113     <para>
1114     Yes.
1115     </para>
1116     <para>
1117     The C++ Standard Library Technical Report adds many new features to 
1118     the library.  The latest version of this effort is described in
1119     <ulink url=
1120          "http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1836.pdf">
1121          Technical Report 1</ulink>.
1122     </para>
1123     <para>
1124     The implementation status of TR1 in libstdc++ can be tracked <link
1125     linkend="manual.intro.status.standard.tr1">on the TR1 status
1126     page</link>.
1127     </para>
1128   </answer>
1129 </qandaentry>
1130
1131 <qandaentry id="faq.get_iso_cxx">
1132   <question id="q-get_iso_cxx">
1133     <para>How do I get a copy of the ISO C++ Standard?
1134     </para>
1135   </question>
1136   <answer id="a-get_iso_cxx">
1137     <para>
1138     Copies of the full ISO 14882 standard are available on line via
1139     the ISO mirror site for committee members.  Non-members, or those
1140     who have not paid for the privilege of sitting on the committee
1141     and sustained their two-meeting commitment for voting rights, may
1142     get a copy of the standard from their respective national
1143     standards organization.  In the USA, this national standards
1144     organization is ANSI and their website is
1145     right <ulink url="http://www.ansi.org">here</ulink>.  (And if
1146     you've already registered with them, clicking this link will take
1147     you to directly to the place where you can
1148     <ulink url="http://webstore.ansi.org/ansidocstore/product.asp?sku=ISO%2FIEC+14882%3A2003">buy the standard on-line</ulink>.
1149     </para>
1150     <para>
1151     Who is your country's member body?  Visit the
1152     <ulink url="http://www.iso.ch/">ISO homepage</ulink> and find out!
1153     </para>
1154     <para>
1155     The 2003 version of the standard (the 1998 version plus TC1) is
1156     available in print, ISBN 0-470-84674-7.
1157     </para> 
1158   </answer>
1159 </qandaentry>
1160
1161 <qandaentry id="faq.what_is_abi">
1162   <question id="q-what_is_abi">
1163     <para>
1164       What's an ABI and why is it so messy?
1165     </para>
1166   </question>
1167   <answer id="a-what_is_abi">
1168     <para>
1169     <acronym>ABI</acronym> stands for <quote>Application Binary
1170      Interface</quote>.  Conventionally, it refers to a great
1171     mass of details about how arguments are arranged on the call
1172     stack and/or in registers, and how various types are arranged
1173     and padded in structs.  A single CPU design may suffer
1174     multiple ABIs designed by different development tool vendors
1175     who made different choices, or even by the same vendor for
1176     different target applications or compiler versions.  In ideal
1177     circumstances the CPU designer presents one ABI and all the
1178     OSes and compilers use it.  In practice every ABI omits
1179     details that compiler implementers (consciously or
1180     accidentally) must choose for themselves.
1181     </para>
1182     <para>
1183     That ABI definition suffices for compilers to generate code so a
1184     program can interact safely with an OS and its lowest-level libraries.
1185     Users usually want an ABI to encompass more detail, allowing libraries
1186     built with different compilers (or different releases of the same
1187     compiler!) to be linked together.  For C++, this includes many more
1188     details than for C, and CPU designers (for good reasons elaborated
1189     below) have not stepped up to publish C++ ABIs.  The details include
1190     virtual function implementation, struct inheritance layout, name
1191     mangling, and exception handling.  Such an ABI has been defined for
1192     GNU C++, and is immediately useful for embedded work relying only on
1193     a <quote>free-standing implementation</quote> that doesn't include (much
1194     of) the standard library.  It is a good basis for the work to come.
1195     </para>
1196     <para>
1197     A useful C++ ABI must also incorporate many details of the standard
1198     library implementation.  For a C ABI, the layouts of a few structs
1199     (such as FILE, stat, jmpbuf, and the like) and a few macros suffice.
1200     For C++, the details include the complete set of names of functions
1201     and types used, the offsets of class members and virtual functions,
1202     and the actual definitions of all inlines.  C++ exposes many more
1203     library details to the caller than C does.  It makes defining
1204     a complete ABI a much bigger undertaking, and requires not just
1205     documenting library implementation details, but carefully designing
1206     those details so that future bug fixes and optimizations don't
1207     force breaking the ABI.
1208     </para>
1209     <para>
1210     There are ways to help isolate library implementation details from the
1211     ABI, but they trade off against speed.  Library details used in
1212     inner loops (e.g., getchar) must be exposed and frozen for all
1213     time, but many others may reasonably be kept hidden from user code,
1214     so they may later be changed.  Deciding which, and implementing
1215     the decisions, must happen before you can reasonably document a
1216     candidate C++ ABI that encompasses the standard library.
1217     </para> 
1218   </answer>
1219 </qandaentry>
1220
1221 <qandaentry id="faq.size_equals_capacity">
1222   <question id="q-size_equals_capacity">
1223     <para>
1224       How do I make std::vector&lt;T&gt;::capacity() == std::vector&lt;T&gt;::size?
1225     </para>
1226   </question>
1227   <answer id="a-size_equals_capacity">
1228     <para>
1229     The standard idiom for deallocating a <classname>vector&lt;T&gt;</classname>'s
1230     unused memory is to create a temporary copy of the vector and swap their
1231     contents, e.g. for <classname>vector&lt;T&gt; v</classname>
1232     </para>
1233     <literallayout>
1234      std::vector&lt;T&gt;(v).swap(v);
1235     </literallayout>
1236     <para>
1237     The copy will take O(n) time and the swap is constant time.
1238     </para>
1239     <para>
1240     See <ulink url="../21_strings/howto.html#6">Shrink-to-fit
1241     strings</ulink> for a similar solution for strings.
1242     </para> 
1243   </answer>
1244 </qandaentry>
1245
1246 </qandadiv>
1247
1248
1249 <!-- FAQ ends here -->
1250 </qandaset>
1251
1252 </article>
1253
1254 </book>