2 libstdc++ Frequently Asked Questions
4 The latest version of this document is always available at
5 [1]http://gcc.gnu.org/onlinedocs/libstdc++/faq/. The main
6 documentation page is at
7 [2]http://gcc.gnu.org/onlinedocs/libstdc++/documentation.html.
9 To the [3]libstdc++-v3 homepage.
10 _________________________________________________________________
14 1. [4]General Information
15 1. [5]What is libstdc++-v3?
16 2. [6]Why should I use libstdc++?
17 3. [7]Who's in charge of it?
18 4. [8]How do I get libstdc++?
19 5. [9]When is libstdc++ going to be finished?
20 6. [10]How do I contribute to the effort?
21 7. [11]What happened to libg++? I need that!
22 8. [12]What if I have more questions?
23 9. [13]What are the license terms for libstdc++-v3?
25 1. [15]How do I install libstdc++-v3?
27 3. [17]What is this CVS thing that you keep mentioning?
28 4. [18]How do I know if it works?
29 5. [19]This library is HUGE! And what's libsupc++?
30 3. [20]Platform-Specific Issues
31 1. [21]Can libstdc++-v3 be used with <my favorite compiler>?
34 4. [24]I can't use 'long long' on Solaris
35 5. [25]_XOPEN_SOURCE / _GNU_SOURCE / etc is always defined
36 6. [26]OS X ctype.h is broken! How can I hack it?
37 7. [27]Threading is broken on i386
38 8. [28]Recent GNU/Linux glibc required?
39 9. [29]Can't use wchar_t/wstring on FreeBSD
40 4. [30]Known Bugs and Non-Bugs
41 1. [31]What works already?
42 2. [32]Bugs in gcc/g++ (not libstdc++-v3)
43 3. [33]Bugs in the C++ language/lib specification
44 4. [34]Things in libstdc++ that only look like bugs
45 o [35]reopening a stream fails
46 o [36]-Weffc++ complains too much
47 o [37]"ambiguous overloads" after including an old-style
49 o [38]The g++-3 headers are not ours
50 o [39]compilation errors from streambuf.h
51 o [40]errors about *Concept and constraints in the STL...
52 o [41]program crashes when using library code in a
53 dynamically-loaded library
54 o [42]"memory leaks" in containers
55 5. [43]Aw, that's easy to fix!
57 1. [45]string::iterator is not char*; vector<T>::iterator is not
59 2. [46]What's next after libstdc++-v3?
60 3. [47]What about the STL from SGI?
61 4. [48]Extensions and Backward Compatibility
63 6. [50]Is libstdc++-v3 thread-safe?
64 7. [51]How do I get a copy of the ISO C++ Standard?
65 8. [52]What's an ABI and why is it so messy?
66 _________________________________________________________________
68 1.0 General Information
70 1.1 What is libstdc++-v3?
72 The GNU Standard C++ Library v3 is an ongoing project to implement the
73 ISO 14882 Standard C++ library as described in chapters 17 through 27
74 and annex D. As the library reaches stable plateaus, it is captured in
75 a snapshot and released. The latest release is [53]the fourteenth
76 snapshot but newer versions have been included in recent GCC releases.
77 For those who want to see exactly how far the project has come, or
78 just want the latest bleeding-edge code, the up-to-date source is
79 available over anonymous CVS, and can even be browsed over the Web
82 The older libstdc++-v2 project is no longer maintained; the code has
83 been completely replaced and rewritten. [55]If you are using V2, then
84 you need to report bugs to your system vendor, not to the V3 list.
86 A more formal description of the V3 goals can be found in the official
88 _________________________________________________________________
90 1.2 Why should I use libstdc++?
92 The completion of the ISO C++ standardization gave the C++ community a
93 powerful set of reuseable tools in the form of the C++ Standard
94 Library. However, all existing C++ implementations are (as the Draft
95 Standard used to say) "incomplet and incorrekt," and many suffer from
96 limitations of the compilers that use them.
98 The GNU C/C++/FORTRAN/<pick-a-language> compiler (gcc, g++, etc) is
99 widely considered to be one of the leading compilers in the world. Its
100 development has recently been taken over by the [57]GCC team. All of
101 the rapid development and near-legendary [58]portability that are the
102 hallmarks of an open-source project are being applied to libstdc++.
104 That means that all of the Standard classes and functions (such as
105 string, vector<>, iostreams, and algorithms) will be freely available
106 and fully compliant. Programmers will no longer need to "roll their
107 own" nor be worried about platform-specific incompatibilities.
108 _________________________________________________________________
110 1.3 Who's in charge of it?
112 The libstdc++ project is contributed to by several developers all over
113 the world, in the same way as GCC or Linux. Benjamin Kosnik, Gabriel
114 Dos Reis, Phil Edwards, Ulrich Drepper, Loren James Rittle, and Paolo
115 Carlini are the lead maintainers of the CVS archive.
117 Development and discussion is held on the libstdc++ mailing list.
118 Subscribing to the list, or searching the list archives, is open to
119 everyone. You can read instructions for doing so on the [59]homepage.
120 If you have questions, ideas, code, or are just curious, sign up!
121 _________________________________________________________________
123 1.4 How do I get libstdc++?
125 The [60]homepage has instructions for retrieving the latest CVS
126 sources, and for browsing the CVS sources over the web.
128 Stable versions of libstdc++-v3 are included with releases of [61]the
131 The subset commonly known as the Standard Template Library (chapters
132 23 through 25, mostly) is adapted from the final release of the SGI
134 _________________________________________________________________
136 1.5 When is libstdc++ going to be finished?
138 Nathan Myers gave the best of all possible answers, responding to a
139 Usenet article asking this question: Sooner, if you help.
140 _________________________________________________________________
142 1.6 How do I contribute to the effort?
144 Here is [62]a page devoted to this topic. Subscribing to the mailing
145 list (see above, or the homepage) is a very good idea if you have
146 something to contribute, or if you have spare time and want to help.
147 Contributions don't have to be in the form of source code; anybody who
148 is willing to help write documentation, for example, or has found a
149 bug in code that we all thought was working, is more than welcome!
150 _________________________________________________________________
152 1.7 What happened to libg++? I need that!
154 The most recent libg++ README states that libg++ is no longer being
155 actively maintained. It should not be used for new projects, and is
156 only being kicked along to support older code.
158 The libg++ was designed and created when there was no Standard to
159 provide guidance. Classes like linked lists are now provided for by
160 list<T> and do not need to be created by genclass. (For that matter,
161 templates exist now and are well-supported, whereas genclass (mostly)
164 There are other classes in libg++ that are not specified in the ISO
165 Standard (e.g., statistical analysis). While there are a lot of really
166 useful things that are used by a lot of people (e.g., statistics :-),
167 the Standards Committee couldn't include everything, and so a lot of
168 those "obvious" classes didn't get included.
170 Since libstdc++ is an implementation of the Standard Library, we have
171 no plans at this time to include non-Standard utilities in the
172 implementation, however handy they are. (The extensions provided in
173 the SGI STL aren't maintained by us and don't get a lot of our
174 attention, because they don't require a lot of our time.) It is
175 entirely plausable that the "useful stuff" from libg++ might be
176 extracted into an updated utilities library, but nobody has stated
179 (The [63]Boost site houses free C++ libraries that do varying things,
180 and happened to be started by members of the Standards Committee.
181 Certain "useful stuff" classes will probably migrate there.)
183 For the bold and/or desperate, the [64]GCC extensions page describes
184 where to find the last libg++ source.
185 _________________________________________________________________
187 1.8 What if I have more questions?
189 If you have read the README and RELEASE-NOTES files, and your question
190 remains unanswered, then just ask the mailing list. At present, you do
191 not need to be subscribed to the list to send a message to it. More
192 information is available on the homepage (including how to browse the
193 list archives); to send to the list, use [65]libstdc++@gcc.gnu.org.
195 If you have a question that you think should be included here, or if
196 you have a question about a question/answer here, contact [66]Phil
197 Edwards or [67]Gabriel Dos Reis.
198 _________________________________________________________________
200 1.9 What are the license terms for libstdc++-v3?
202 See [68]our license description for these and related questions.
203 _________________________________________________________________
207 2.1 How do I install libstdc++-v3?
209 Complete instructions are not given here (this is a FAQ, not an
210 installation document), but the tools required are few:
211 * A 3.x release of GCC. Note that building GCC is much easier and
212 more automated than building the GCC 2.[78] series was. If you are
213 using GCC 2.95, you can still build earlier snapshots of
215 * GNU Make is recommended, but should not be required.
216 * The GNU Autotools are needed if you are messing with the configury
219 The file [69]documentation.html provides a good overview of the steps
220 necessary to build, install, and use the library. Instructions for
221 configuring the library with new flags such as --enable-threads are
222 there also, as well as patches and instructions for working with GCC
225 The top-level install.html and [70]RELEASE-NOTES files contain the
226 exact build and installation instructions. You may wish to browse
227 those files over CVSweb ahead of time to get a feel for what's
228 required. RELEASE-NOTES is located in the ".../docs/17_intro/"
229 directory of the distribution.
230 _________________________________________________________________
234 This question has become moot and has been removed. The stub is here
235 to preserve numbering (and hence links/bookmarks).
236 _________________________________________________________________
238 2.3 What is this CVS thing that you keep mentioning?
240 The Concurrent Versions System is one of several revision control
241 packages. It was selected for GNU projects because it's free (speech),
242 free (beer), and very high quality. The [71]CVS entry in the GNU
243 software catalogue has a better description as well as a [72]link to
246 The "anonymous client checkout" feature of CVS is similar to anonymous
247 FTP in that it allows anyone to retrieve the latest libstdc++ sources.
249 After the first of April, American users will have a "/pharmacy"
250 command-line option...
251 _________________________________________________________________
253 2.4 How do I know if it works?
255 libstdc++-v3 comes with its own testsuite. You do not need to actually
256 install the library ("make install") to run the testsuite, but you do
257 need DejaGNU, as described [73]here.
259 To run the testsuite on the library after building it, use "make
260 check" while in your build directory. To run the testsuite on the
261 library after building and installing it, use "make check-install"
264 If you find bugs in the testsuite programs themselves, or if you think
265 of a new test program that should be added to the suite, please write
266 up your idea and send it to the list!
267 _________________________________________________________________
269 2.5 This library is HUGE! And what's libsupc++?
271 Usually the size of libraries on disk isn't noticeable. When a link
272 editor (or simply "linker") pulls things from a static archive
273 library, only the necessary object files are copied into your
274 executable, not the entire library. Unfortunately, even if you only
275 need a single function or variable from an object file, the entire
276 object file is extracted. (There's nothing unique to C++ or
277 libstdc++-v3 about this; it's just common behavior, given here for
280 Some of the object files which make up libstdc++.a are rather large.
281 If you create a statically-linked executable with -static, those large
282 object files are suddenly part of your executable. Historically the
283 best way around this was to only place a very few functions (often
284 only a single one) in each source/object file; then extracting a
285 single function is the same as extracting a single .o file. For
286 libstdc++-v3 this is only possible to a certain extent; the object
287 files in question contain template classes and template functions,
288 pre-instantiated, and splitting those up causes severe maintenance
291 It's not a bug, and it's not really a problem. Nevertheless, some
292 people don't like it, so here are two pseudo-solutions:
294 If the only functions from libstdc++.a which you need are language
295 support functions (those listed in [74]clause 18 of the standard,
296 e.g., new and delete), then try linking against libsupc++.a (usually
297 specifying -lsupc++ when calling g++ for the final link step will do
298 it). This library contains only those support routines, one per object
299 file. But if you are using anything from the rest of the library, such
300 as IOStreams or vectors, then you'll still need pieces from
303 The second method is one we hope to incorporate into the library build
304 process. Some platforms can place each function and variable into its
305 own section in a .o file. The GNU linker can then perform garbage
306 collection on unused sections; this reduces the situation to only
307 copying needed functions into the executable, as before, but all
308 happens automatically.
310 Unfortunately the garbage collection in GNU ld is buggy; sections
311 (corresponding to functions and variables) which are used are
312 mistakenly removed, leading to horrible crashes when your executable
313 starts up. For the time being, this feature is not used when building
315 _________________________________________________________________
317 3.0 Platform-Specific Issues
319 3.1 Can libstdc++-v3 be used with <my favorite compiler>?
323 Because GCC advances so rapidly, development and testing of libstdc++
324 is being done almost entirely under that compiler. If you are curious
325 about whether other, lesser compilers (*grin*) support libstdc++, you
326 are more than welcome to try. Configuring and building the library
327 (see above) will still require certain tools, however. Also keep in
328 mind that building libstdc++ does not imply that your compiler will be
329 able to use all of the features found in the C++ Standard Library.
331 Since the goal of ISO Standardization is for all C++ implementations
332 to be able to share code, the final libstdc++ should, in theory, be
333 usable under any ISO-compliant compiler. It will still be targeted and
334 optimized for GCC/g++, however.
335 _________________________________________________________________
339 This question has become moot and has been removed. The stub is here
340 to preserve numbering (and hence links/bookmarks).
341 _________________________________________________________________
345 This question has become moot and has been removed. The stub is here
346 to preserve numbering (and hence links/bookmarks).
347 _________________________________________________________________
349 3.4 I can't use 'long long' on Solaris
351 By default we try to support the C99 long long type. This requires
352 that certain functions from your C library be present.
354 Up through release 3.0.2 the tests performed were too general, and
355 this feature was disabled when it did not need to be. The most
356 commonly reported platform affected was Solaris.
358 This has been fixed for 3.0.3 and onwards.
359 _________________________________________________________________
361 3.5 _XOPEN_SOURCE / _GNU_SOURCE / etc is always defined
363 On Solaris, g++ (but not gcc) always defines the preprocessor macro
364 _XOPEN_SOURCE. On GNU/Linux, the same happens with _GNU_SOURCE. (This
365 is not an exhaustive list; other macros and other platforms are also
368 These macros are typically used in C library headers, guarding new
369 versions of functions from their older versions. The C++ standard
370 library includes the C standard library, but it requires the C90
371 version, which for backwards-compatability reasons is often not the
372 default for many vendors.
374 More to the point, the C++ standard requires behavior which is only
375 available on certain platforms after certain symbols are defined.
376 Usually the issue involves I/O-related typedefs. In order to ensure
377 correctness, the compiler simply predefines those symbols.
379 Note that it's not enough to #define them only when the library is
380 being built (during installation). Since we don't have an 'export'
381 keyword, much of the library exists as headers, which means that the
382 symbols must also be defined as your programs are parsed and compiled.
384 To see which symbols are defined, look for CPLUSPLUS_CPP_SPEC in the
385 gcc config headers for your target (and try changing them to see what
386 happens when building complicated code). You can also run "g++ -E -dM
387 - < /dev/null" to display a list of predefined macros for any
388 particular installation.
390 This has been discussed on the mailing lists [75]quite a bit.
392 This method is something of a wart. We'd like to find a cleaner
393 solution, but nobody yet has contributed the time.
394 _________________________________________________________________
396 3.6 OS X ctype.h is broken! How can I hack it?
398 This is a long-standing bug in the OS X support. Fortunately, the
399 patch is quite simple, and well-known. [76]Here's a link to the
401 _________________________________________________________________
403 3.7 Threading is broken on i386
405 Support for atomic integer operations is/was broken on i386 platforms.
406 The assembly code accidentally used opcodes that are only available on
407 the i486 and later. So if you configured GCC to target, for example,
408 i386-linux, but actually used the programs on an i686, then you would
409 encounter no problems. Only when actually running the code on a i386
410 will the problem appear.
412 This is fixed in 3.2.2.
413 _________________________________________________________________
415 3.8 Recent GNU/Linux glibc required?
417 When running on GNU/Linux, libstdc++ 3.2.1 (shared library version
418 5.0.1) and later uses localization and formatting code from the system
419 C library (glibc) version 2.2.5. That version of glibc is over a year
420 old and contains necessary bugfixes. Many GNU/Linux distros make glibc
421 version 2.3.x available now.
423 The guideline is simple: the more recent the C++ library, the more
424 recent the C library. (This is also documented in the main GCC
425 installation instructions.)
426 _________________________________________________________________
428 3.9 Can't use wchar_t/wstring on FreeBSD
430 At the moment there are a few problems in FreeBSD's support for wide
431 character functions, and as a result the libstdc++ configury decides
432 that wchar_t support should be disabled. Once the underlying problems
433 are fixed in FreeBSD (soon), the library support will automatically
436 You can fix the problems yourself, and learn more about the situation,
437 by reading [77]this short thread ("_GLIBCPP_USE_WCHAR_T undefined in
438 FreeBSD's c++config.h?").
439 _________________________________________________________________
441 4.0 Known Bugs and Non-Bugs
443 Note that this section can get rapdily outdated -- such is the nature
444 of an open-source project. For the latest information, join the
445 mailing list or look through recent archives. The RELEASE- NOTES and
446 BUGS files are generally kept up-to-date.
448 For 3.0.1, the most common "bug" is an apparently missing "../" in
449 include/Makefile, resulting in files like gthr.h and gthr-single.h not
450 being found. Please read [78]the configuration instructions for GCC,
451 specifically the part about configuring in a separate build directory,
452 and how strongly recommended it is. Building in the source directory
453 is fragile, is rarely tested, and tends to break, as in this case.
454 This was fixed for 3.0.2.
456 For 3.1, the most common "bug" is a parse error when using <fstream>,
457 ending with a message, "bits/basic_file.h:52: parse error before `{'
458 token." Please read [79]the installation instructions for GCC,
459 specifically the part about not installing newer versions on top of
460 older versions. If you install 3.1 over a 3.0.x release, then the
461 wrong basic_file.h header will be found (its location changed between
464 Please do not report these as bugs. We know about them. Reporting this
465 -- or any other problem that's already been fixed -- hinders the
466 development of GCC, because we have to take time to respond to your
469 4.1 What works already?
471 Short answer: Pretty much everything works except for some corner
472 cases. Also, localization is incomplete. For whether it works well, or
473 as you expect it to work, see 5.2.
475 Long answer: See the docs/html/17_intro/CHECKLIST file, which is badly
478 What follows is a verbatim clip from the "Status" section of the
479 RELEASE-NOTES for the latest snapshot. For a list of fixed bugs, see
482 _________________________________________________________________
484 4.2 Bugs in gcc/g++ (not libstdc++-v3)
486 This is by no means meant to be complete nor exhaustive, but mentions
487 some problems that users may encounter when building or using
488 libstdc++. If you are experiencing one of these problems, you can find
489 more information on the libstdc++ and the GCC mailing lists.
491 Before reporting a bug, examine the [80]bugs database with the
492 category set to "libstdc++". The BUGS file in the source tree also
493 tracks known serious problems.
494 * Debugging is problematic, due to bugs in line-number generation
495 (mostly fixed in the compiler) and gdb lagging behind the compiler
496 (lack of personnel). We recommend configuring the compiler using
497 --with-dwarf2 if the DWARF2 debugging format is not already the
498 default on your platform. Also, [81]changing your GDB settings can
499 have a profound effect on your C++ debugging experiences. :-)
500 _________________________________________________________________
502 4.3 Bugs in the C++ language/lib specification
504 Yes, unfortunately, there are some. In a [82]message to the list,
505 Nathan Myers announced that he has started a list of problems in the
506 ISO C++ Standard itself, especially with regard to the chapters that
507 concern the library. The list itself is [83]posted on his website.
508 Developers who are having problems interpreting the Standard may wish
509 to consult his notes.
511 For those people who are not part of the ISO Library Group (i.e.,
512 nearly all of us needing to read this page in the first place :-), a
513 public list of the library defects is occasionally published [84]here.
514 Some of these have resulted in [85]code changes.
515 _________________________________________________________________
517 4.4 Things in libstdc++ that only look like bugs
519 There are things which are not bugs in the compiler (4.2) nor the
520 language specification (4.3), but aren't really bugs in libstdc++,
521 either. Really! Please do not report these as bugs.
523 -Weffc++ The biggest of these is the quadzillions of warnings about
524 the library headers emitted when -Weffc++ is used. Making libstdc++
525 "-Weffc++-clean" is not a goal of the project, for a few reasons.
526 Mainly, that option tries to enforce object-oriented programming,
527 while the Standard Library isn't necessarily trying to be OO.
529 reopening a stream fails Did I just say that -Weffc++ was our biggest
530 false-bug report? I lied. (It used to be.) Today it seems to be
531 reports that after executing a sequence like
534 std::fstream fs("a_file");
536 // . do things with fs...
539 fs.open("a_new_file");
541 all operations on the re-opened fs will fail, or at least act very
542 strangely. Yes, they often will, especially if fs reached the EOF
543 state on the previous file. The reason is that the state flags are not
544 cleared on a successful call to open(). The standard unfortunately did
545 not specify behavior in this case, and to everybody's great sorrow,
546 the [86]proposed LWG resolution in DR #22 is to leave the flags
547 unchanged. You must insert a call to fs.clear() between the calls to
548 close() and open(), and then everything will work like we all expect
551 rel_ops Another is the rel_ops namespace and the template comparison
552 operator functions contained therein. If they become visible in the
553 same namespace as other comparison functions (e.g., 'using' them and
554 the <iterator> header), then you will suddenly be faced with huge
555 numbers of ambiguity errors. This was discussed on the -v3 list;
556 Nathan Myers [87]sums things up here. The collisions with
557 vector/string iterator types have been fixed for 3.1.
559 The g++-3 headers are not ours
561 If you have found an extremely broken header file which is causing
562 problems for you, look carefully before submitting a "high" priority
563 bug report (which you probably shouldn't do anyhow; see the last
564 paragraph of the page describing [88]the GCC bug database).
566 If the headers are in ${prefix}/include/g++-3, or if the installed
567 library's name looks like libstdc++-2.10.a or libstdc++-libc6-2.10.so,
568 then you are using the old libstdc++-v2 library, which is nonstandard
569 and unmaintained. Do not report problems with -v2 to the -v3 mailing
572 For GCC versions 3.0 and 3.1 the libstdc++-v3 header files are
573 installed in ${prefix}/include/g++-v3 (see the 'v'?). Starting with
574 version 3.2 the headers are installed in
575 ${prefix}/include/c++/${version} as this prevents headers from
576 previous versions being found by mistake.
578 glibc If you're on a GNU/Linux system and have just upgraded to glibc
579 2.2, but are still using gcc 2.95.2, then you should have read the
580 glibc FAQ, specifically 2.34:
581 2.34. When compiling C++ programs, I get a compilation error in streambuf.h.
583 {BH} You are using g++ 2.95.2? After upgrading to glibc 2.2, you need to
584 apply a patch to the include files in /usr/include/g++, because the fpos_t
585 type has changed in glibc 2.2. The patch is at
586 http://clisp.cons.org/~haible/gccinclude-glibc-2.2-compat.diff
589 Note that 2.95.x shipped with the [89]old v2 library which is no
590 longer maintained. Also note that gcc 2.95.3 fixes this problem, but
591 requires a separate patch for libstdc++-v3.
593 concept checks If you see compilation errors containing messages about
594 fooConcept and a constraints member function, then most likely you
595 have violated one of the requirements for types used during
596 instantiation of template containers and functions. For example,
597 EqualityComparableConcept appears if your types must be comparable
598 with == and you have not provided this capability (a typo, or wrong
599 visibility, or you just plain forgot, etc).
601 More information, including how to optionally enable/disable the
602 checks, is available [90]here.
604 dlopen/dlsym If you are using the C++ library across
605 dynamically-loaded objects, make certain that you are passing the
606 correct options when compiling and linking:
607 // compile your library components
613 // create your library
614 g++ -fPIC -shared -rdynamic -o libfoo.so a.o b.o ... z.o
616 // link the executable
617 g++ -fPIC -rdynamic -o foo ... -L. -lfoo -ldl
619 "memory leaks" in containers A few people have reported that the
620 standard containers appear to leak memory when tested with memory
621 checkers such as [91]valgrind. The library's default allocators keep
622 free memory in a pool for later reuse, rather than returning it to the
623 OS. Although this memory is always reachable by the library and is
624 never lost, memory debugging tools can report it as a leak. If you
625 want to test the library for memory leaks please read [92]Tips for
626 memory leak hunting first.
627 _________________________________________________________________
629 4.5 Aw, that's easy to fix!
631 If you have found a bug in the library and you think you have a
632 working fix, then send it in! The main GCC site has a page on
633 [93]submitting patches that covers the procedure, but for libstdc++
634 you should also send the patch to our mailing list in addition to the
635 GCC patches mailing list. The libstdc++ [94]contributors' page also
636 talks about how to submit patches.
638 In addition to the description, the patch, and the ChangeLog entry, it
639 is a Good Thing if you can additionally create a small test program to
640 test for the presence of the bug that your patch fixes. Bugs have a
641 way of being reintroduced; if an old bug creeps back in, it will be
642 caught immediately by the [95]testsuite -- but only if such a test
644 _________________________________________________________________
648 5.1 string::iterator is not char*; vector<T>::iterator is not T*
650 If you have code that depends on container<T> iterators being
651 implemented as pointer-to-T, your code is broken.
653 While there are arguments for iterators to be implemented in that
654 manner, A) they aren't very good ones in the long term, and B) they
655 were never guaranteed by the Standard anyway. The type-safety achieved
656 by making iterators a real class rather than a typedef for T*
657 outweighs nearly all opposing arguments.
659 Code which does assume that a vector iterator i is a pointer can often
660 be fixed by changing i in certain expressions to &*i . Future
661 revisions of the Standard are expected to bless this usage for
662 vector<> (but not for basic_string<>).
663 _________________________________________________________________
665 5.2 What's next after libstdc++-v3?
667 Hopefully, not much. The goal of libstdc++-v3 is to produce a
668 fully-compliant, fully-portable Standard Library. After that, we're
669 mostly done: there won't be any more compliance work to do. However:
670 1. The ISO Committee will meet periodically to review Defect Reports
671 in the C++ Standard. Undoubtedly some of these will result in
672 changes to the Standard, which will be reflected in patches to
673 libstdc++. Some of that is already happening, see 4.2. Some of
674 those changes are being predicted by the library maintainers, and
675 we add code to the library based on what the current proposed
676 resolution specifies. Those additions are listed in [96]the
678 2. Performance tuning. Lots of performance tuning. This too is
679 already underway for post-3.0 releases, starting with memory
680 expansion in container classes and buffer usage in synchronized
682 3. An ABI for libstdc++ is being developed, so that multiple
683 binary-incompatible copies of the library can be replaced with a
684 single backwards-compatible library, like libgcc_s.so is.
685 4. The current libstdc++ contains extensions to the Library which
686 must be explicitly requested by client code (for example, the hash
687 tables from SGI). Other extensions may be added to libstdc++-v3 if
688 they seem to be "standard" enough. (For example, the "long long"
689 type from C99.) Bugfixes and rewrites (to improve or fix thread
690 safety, for instance) will of course be a continuing task.
692 [97]This question about the next libstdc++ prompted some brief but
693 interesting [98]speculation.
694 _________________________________________________________________
696 5.3 What about the STL from SGI?
698 The [99]STL from SGI, version 3.3, was the most recent merge of the
699 STL codebase. The code in libstdc++ contains many fixes and changes,
700 and it is very likely that the SGI code is no longer under active
701 development. We expect that no future merges will take place.
703 In particular, string is not from SGI and makes no use of their "rope"
704 class (which is included as an optional extension), nor is valarray
705 and some others. Classes like vector<> are, however we have made
706 significant changes to them since then.
708 The FAQ for SGI's STL (one jump off of their main page) is recommended
710 _________________________________________________________________
712 5.4 Extensions and Backward Compatibility
714 Headers in the ext and backward subdirectories should be referred to
715 by their relative paths:
716 #include <ext/hash_map>
718 rather than using -I or other options. This is more portable and
719 forward-compatible. (The situation is the same as that of other
720 headers whose directories are not searched directly, e.g.,
721 <sys/stat.h>, <X11/Xlib.h>.
723 The extensions are no longer in the global or std namespaces, instead
724 they are declared in the __gnu_cxx namespace. For maximum portability,
725 consider defining a namespace alias to use to talk about extensions,
729 #include <hash_map.h>
730 namespace Sgi { using ::hash_map; }; // inherit globals
732 #include <ext/hash_map>
733 #if __GNUC_MINOR__ == 0
734 namespace Sgi = std; // GCC 3.0
736 namespace Sgi = ::__gnu_cxx; // GCC 3.1 and later
739 #else // ... there are other compilers, right?
743 Sgi::hash_map<int,int> my_map;
745 This is a bit cleaner than defining typedefs for all the
746 instantiations you might need.
748 Extensions to the library have [100]their own page.
749 _________________________________________________________________
753 This question has become moot and has been removed. The stub is here
754 to preserve numbering (and hence links/bookmarks).
755 _________________________________________________________________
757 5.6 Is libstdc++-v3 thread-safe?
759 libstdc++-v3 strives to be thread-safe when all of the following
761 * The system's libc is itself thread-safe,
762 * gcc -v reports a thread model other than 'single',
763 * [pre-3.3 only] a non-generic implementation of atomicity.h exists
764 for the architecture in question.
766 The user-code must guard against concurrent method calls which may
767 access any particular library object's state. Typically, the
768 application programmer may infer what object locks must be held based
769 on the objects referenced in a method call. Without getting into great
770 detail, here is an example which requires user-level locks:
771 library_class_a shared_object_a;
774 library_class_b *object_b = new library_class_b;
775 shared_object_a.add_b (object_b); // must hold lock for shared_object_
777 shared_object_a.mutate (); // must hold lock for shared_object_
781 // Multiple copies of thread_main() are started in independent threads.
783 Under the assumption that object_a and object_b are never exposed to
784 another thread, here is an example that should not require any
787 library_class_a object_a;
788 library_class_b *object_b = new library_class_b;
789 object_a.add_b (object_b);
793 All library objects are safe to use in a multithreaded program as long
794 as each thread carefully locks out access by any other thread while it
795 uses any object visible to another thread, i.e., treat library objects
796 like any other shared resource. In general, this requirement includes
797 both read and write access to objects; unless otherwise documented as
798 safe, do not assume that two threads may access a shared standard
799 library object at the same time.
801 See chapters [101]17 (library introduction), [102]23 (containers), and
802 [103]27 (I/O) for more information.
803 _________________________________________________________________
805 5.7 How do I get a copy of the ISO C++ Standard?
807 Copies of the full ISO 14882 standard are available on line via the
808 ISO mirror site for committee members. Non-members, or those who have
809 not paid for the privilege of sitting on the committee and sustained
810 their two-meeting commitment for voting rights, may get a copy of the
811 standard from their respective national standards organization. In the
812 USA, this national standards organization is ANSI and their website is
813 right [104]here. (And if you've already registered with them, clicking
814 this link will take you to directly to the place where you can
815 [105]buy the standard on-line.
817 Who is your country's member body? Visit the [106]ISO homepage and
819 _________________________________________________________________
821 5.8 What's an ABI and why is it so messy?
823 "ABI" stands for "Application Binary Interface." Conventionally, it
824 refers to a great mass of details about how arguments are arranged on
825 the call stack and/or in registers, and how various types are arranged
826 and padded in structs. A single CPU design may suffer multiple ABIs
827 designed by different development tool vendors who made different
828 choices, or even by the same vendor for different target applications
829 or compiler versions. In ideal circumstances the CPU designer presents
830 one ABI and all the OSes and compilers use it. In practice every ABI
831 omits details that compiler implementers (consciously or accidentally)
832 must choose for themselves.
834 That ABI definition suffices for compilers to generate code so a
835 program can interact safely with an OS and its lowest-level libraries.
836 Users usually want an ABI to encompass more detail, allowing libraries
837 built with different compilers (or different releases of the same
838 compiler!) to be linked together. For C++, this includes many more
839 details than for C, and CPU designers (for good reasons elaborated
840 below) have not stepped up to publish C++ ABIs. The details include
841 virtual function implementation, struct inheritance layout, name
842 mangling, and exception handling. Such an ABI has been defined for GNU
843 C++, and is immediately useful for embedded work relying only on a
844 "free-standing implementation" that doesn't include (much of) the
845 standard library. It is a good basis for the work to come.
847 A useful C++ ABI must also incorporate many details of the standard
848 library implementation. For a C ABI, the layouts of a few structs
849 (such as FILE, stat, jmpbuf, and the like) and a few macros suffice.
850 For C++, the details include the complete set of names of functions
851 and types used, the offsets of class members and virtual functions,
852 and the actual definitions of all inlines. C++ exposes many more
853 library details to the caller than C does. It makes defining a
854 complete ABI a much bigger undertaking, and requires not just
855 documenting library implementation details, but carefully designing
856 those details so that future bug fixes and optimizations don't force
859 There are ways to help isolate library implementation details from the
860 ABI, but they trade off against speed. Library details used in inner
861 loops (e.g., getchar) must be exposed and frozen for all time, but
862 many others may reasonably be kept hidden from user code, so they may
863 later be changed. Deciding which, and implementing the decisions, must
864 happen before you can reasonably document a candidate C++ ABI that
865 encompasses the standard library.
866 _________________________________________________________________
868 See [107]license.html for copying conditions. Comments and suggestions
869 are welcome, and may be sent to [108]the libstdc++ mailing list.
873 1. http://gcc.gnu.org/onlinedocs/libstdc++/faq/
874 2. http://gcc.gnu.org/onlinedocs/libstdc++/documentation.html
875 3. http://gcc.gnu.org/libstdc++/
876 4. ../faq/index.html#1_0
877 5. ../faq/index.html#1_1
878 6. ../faq/index.html#1_2
879 7. ../faq/index.html#1_3
880 8. ../faq/index.html#1_4
881 9. ../faq/index.html#1_5
882 10. ../faq/index.html#1_6
883 11. ../faq/index.html#1_7
884 12. ../faq/index.html#1_8
885 13. ../faq/index.html#1_9
886 14. ../faq/index.html#2_0
887 15. ../faq/index.html#2_1
888 16. ../faq/index.html#2_2
889 17. ../faq/index.html#2_3
890 18. ../faq/index.html#2_4
891 19. ../faq/index.html#2_5
892 20. ../faq/index.html#3_0
893 21. ../faq/index.html#3_1
894 22. ../faq/index.html#3_2
895 23. ../faq/index.html#3_3
896 24. ../faq/index.html#3_4
897 25. ../faq/index.html#3_5
898 26. ../faq/index.html#3_6
899 27. ../faq/index.html#3_7
900 28. ../faq/index.html#3_8
901 29. ../faq/index.html#3_9
902 30. ../faq/index.html#4_0
903 31. ../faq/index.html#4_1
904 32. ../faq/index.html#4_2
905 33. ../faq/index.html#4_3
906 34. ../faq/index.html#4_4
907 35. ../faq/index.html#4_4_iostreamclear
908 36. ../faq/index.html#4_4_Weff
909 37. ../faq/index.html#4_4_rel_ops
910 38. ../faq/index.html#4_4_interface
911 39. ../faq/index.html#4_4_glibc
912 40. ../faq/index.html#4_4_checks
913 41. ../faq/index.html#4_4_dlsym
914 42. ../faq/index.html#4_4_leak
915 43. ../faq/index.html#4_5
916 44. ../faq/index.html#5_0
917 45. ../faq/index.html#5_1
918 46. ../faq/index.html#5_2
919 47. ../faq/index.html#5_3
920 48. ../faq/index.html#5_4
921 49. ../faq/index.html#5_5
922 50. ../faq/index.html#5_6
923 51. ../faq/index.html#5_7
924 52. ../faq/index.html#5_8
925 53. http://gcc.gnu.org/libstdc++/index.html#download
926 54. ../faq/index.html#1_4
927 55. ../faq/index.html#4_4_interface
928 56. ../17_intro/DESIGN
929 57. http://gcc.gnu.org/
930 58. http://gcc.gnu.org/gcc-3.0/buildstat.html
931 59. http://gcc.gnu.org/libstdc++/
932 60. http://gcc.gnu.org/libstdc++/
933 61. http://gcc.gnu.org/releases.html
934 62. ../17_intro/contribute.html
935 63. http://www.boost.org/
936 64. http://gcc.gnu.org/extensions.html
937 65. mailto:libstdc++@gcc.gnu.org
938 66. mailto:pme@gcc.gnu.org
939 67. mailto:gdr@gcc.gnu.org
940 68. ../17_intro/license.html
941 69. ../documentation.html
942 70. ../17_intro/RELEASE-NOTES
943 71. http://www.gnu.org/software/cvs/cvs.html
944 72. http://www.cvshome.org/
945 73. http://gcc.gnu.org/install/test.html
946 74. ../18_support/howto.html
947 75. http://gcc.gnu.org/cgi-bin/htsearch?method=and&format=builtin-long&sort=score&words=_XOPEN_SOURCE+Solaris
948 76. http://gcc.gnu.org/ml/gcc/2002-03/msg00817.html
949 77. http://gcc.gnu.org/ml/libstdc++/2003-02/subjects.html#00286
950 78. http://gcc.gnu.org/install/configure.html
951 79. http://gcc.gnu.org/install/
952 80. http://gcc.gnu.org/bugs.html
953 81. http://gcc.gnu.org/ml/libstdc++/2002-02/msg00034.html
954 82. http://gcc.gnu.org/ml/libstdc++/1998/msg00006.html
955 83. http://www.cantrip.org/draft-bugs.txt
956 84. http://anubis.dkuug.dk/jtc1/sc22/wg21/
957 85. ../faq/index.html#5_2
958 86. ../ext/howto.html#5
959 87. http://gcc.gnu.org/ml/libstdc++/2001-01/msg00247.html
960 88. http://gcc.gnu.org/gnatswrite.html
961 89. ../faq/index.html#4_4_interface
962 90. ../19_diagnostics/howto.html#3
963 91. http://developer.kde.org/~sewardj/
964 92. ../debug.html#mem
965 93. http://gcc.gnu.org/contribute.html
966 94. ../17_intro/contribute.html
967 95. ../faq/index.html#2_4
968 96. ../ext/howto.html#5
969 97. http://gcc.gnu.org/ml/libstdc++/1999/msg00080.html
970 98. http://gcc.gnu.org/ml/libstdc++/1999/msg00084.html
971 99. http://www.sgi.com/Technology/STL/
972 100. ../ext/howto.html
973 101. ../17_intro/howto.html#3
974 102. ../23_containers/howto.html#3
975 103. ../27_io/howto.html#9
976 104. http://www.ansi.org/
977 105. http://webstore.ansi.org/ansidocstore/product.asp?sku=ISO%2FIEC+14882%2D1998
978 106. http://www.iso.ch/
979 107. ../17_intro/license.html
980 108. mailto:libstdc++@gcc.gnu.org