11debfc3dSmrg<book xmlns="http://docbook.org/ns/docbook" version="5.0"> 21debfc3dSmrg 31debfc3dSmrg<article xml:id="faq" xreflabel="Frequently Asked Questions"> 41debfc3dSmrg<?dbhtml filename="faq.html"?> 51debfc3dSmrg 61debfc3dSmrg<info><title>Frequently Asked Questions</title> 71debfc3dSmrg 81debfc3dSmrg <copyright> 91debfc3dSmrg <year> 10a2dc1f3fSmrg 2008-2018 111debfc3dSmrg </year> 121debfc3dSmrg <holder> 13a2dc1f3fSmrg <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://www.fsf.org">FSF</link> 141debfc3dSmrg </holder> 151debfc3dSmrg </copyright> 161debfc3dSmrg</info> 171debfc3dSmrg 181debfc3dSmrg<!-- FAQ starts here --> 191debfc3dSmrg<qandaset xml:id="faq.faq"> 201debfc3dSmrg 211debfc3dSmrg<!-- General Information --> 221debfc3dSmrg<qandadiv xml:id="faq.info" xreflabel="General Information"> 231debfc3dSmrg 241debfc3dSmrg<qandaentry xml:id="faq.what"> 251debfc3dSmrg <question xml:id="faq.what.q"> 261debfc3dSmrg <para> 271debfc3dSmrg What is libstdc++? 281debfc3dSmrg </para> 291debfc3dSmrg </question> 301debfc3dSmrg <answer xml:id="faq.what.a"> 311debfc3dSmrg <para> 321debfc3dSmrg The GNU Standard C++ Library v3 is an ongoing project to 33a2dc1f3fSmrg implement the ISO 14882 C++ Standard Library as described in 34a2dc1f3fSmrg clauses 20 through 33 and annex D (prior to the 2017 standard 35a2dc1f3fSmrg the library clauses started with 17). For those who want to see 361debfc3dSmrg exactly how far the project has come, or just want the latest 37a2dc1f3fSmrg bleeding-edge code, the up-to-date source can be cloned via 38a2dc1f3fSmrg <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://gcc.gnu.org/git.html">Git</link>. 39a2dc1f3fSmrg </para> 40a2dc1f3fSmrg 41a2dc1f3fSmrg <para> 42a2dc1f3fSmrg N.B. The library is called libstdc++ <emphasis>not</emphasis> stdlibc++. 431debfc3dSmrg </para> 441debfc3dSmrg </answer> 451debfc3dSmrg</qandaentry> 461debfc3dSmrg 471debfc3dSmrg<qandaentry xml:id="faq.why"> 481debfc3dSmrg <question xml:id="q-why"> 491debfc3dSmrg <para> 501debfc3dSmrg Why should I use libstdc++? 511debfc3dSmrg </para> 521debfc3dSmrg </question> 531debfc3dSmrg <answer xml:id="a-why"> 541debfc3dSmrg <para> 551debfc3dSmrg The completion of the initial ISO C++ standardization effort gave the C++ 561debfc3dSmrg community a powerful set of reuseable tools in the form of the C++ 571debfc3dSmrg Standard Library. However, for several years C++ implementations were 581debfc3dSmrg (as the Draft Standard used to say) <quote>incomplet and 591debfc3dSmrg incorrekt</quote>, and many suffered from limitations of the compilers 601debfc3dSmrg that used them. 611debfc3dSmrg </para> 621debfc3dSmrg <para> 631debfc3dSmrg The GNU compiler collection 641debfc3dSmrg (<command>gcc</command>, <command>g++</command>, etc) is widely 651debfc3dSmrg considered to be one of the leading compilers in the world. Its 661debfc3dSmrg development is overseen by the 671debfc3dSmrg <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://gcc.gnu.org/">GCC team</link>. All of 681debfc3dSmrg the rapid development and near-legendary 691debfc3dSmrg <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://gcc.gnu.org/buildstat.html">portability</link> 701debfc3dSmrg that are the hallmarks of an open-source project are applied to libstdc++. 711debfc3dSmrg </para> 721debfc3dSmrg <para> 73a2dc1f3fSmrg All of the standard classes and functions from C++98/C++03, C++11 and C++14 741debfc3dSmrg (such as <classname>string</classname>, 751debfc3dSmrg <classname>vector<></classname>, iostreams, algorithms etc.) 76a2dc1f3fSmrg are freely available and attempt to be fully compliant. 771debfc3dSmrg Work is ongoing to complete support for the current revision of the 781debfc3dSmrg ISO C++ Standard. 791debfc3dSmrg </para> 801debfc3dSmrg </answer> 811debfc3dSmrg</qandaentry> 821debfc3dSmrg 831debfc3dSmrg<qandaentry xml:id="faq.who"> 841debfc3dSmrg <question xml:id="q-who"> 851debfc3dSmrg <para> 861debfc3dSmrg Who's in charge of it? 871debfc3dSmrg </para> 881debfc3dSmrg </question> 891debfc3dSmrg <answer xml:id="a-who"> 901debfc3dSmrg <para> 911debfc3dSmrg The libstdc++ project is contributed to by several developers 921debfc3dSmrg all over the world, in the same way as GCC or the Linux kernel. 931debfc3dSmrg The current maintainers are listed in the 941debfc3dSmrg <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://gcc.gnu.org/viewcvs/gcc/trunk/MAINTAINERS?view=co"><filename>MAINTAINERS</filename></link> 951debfc3dSmrg file (look for "c++ runtime libs"). 961debfc3dSmrg </para> 971debfc3dSmrg <para> 981debfc3dSmrg Development and discussion is held on the libstdc++ mailing 991debfc3dSmrg list. Subscribing to the list, or searching the list 1001debfc3dSmrg archives, is open to everyone. You can read instructions for 1011debfc3dSmrg doing so on the <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://gcc.gnu.org/lists.html">GCC mailing lists</link> page. 1021debfc3dSmrg If you have questions, ideas, code, or are just curious, sign up! 1031debfc3dSmrg </para> 1041debfc3dSmrg </answer> 1051debfc3dSmrg</qandaentry> 1061debfc3dSmrg 1071debfc3dSmrg<qandaentry xml:id="faq.when"> 1081debfc3dSmrg <question xml:id="q-when"> 1091debfc3dSmrg <para> 1101debfc3dSmrg When is libstdc++ going to be finished? 1111debfc3dSmrg </para> 1121debfc3dSmrg </question> 1131debfc3dSmrg <answer xml:id="a-when"> 1141debfc3dSmrg <para> 1151debfc3dSmrg Nathan Myers gave the best of all possible answers, responding to 1161debfc3dSmrg a Usenet article asking this question: <emphasis>Sooner, if you 1171debfc3dSmrg help.</emphasis> 1181debfc3dSmrg </para> 1191debfc3dSmrg </answer> 1201debfc3dSmrg</qandaentry> 1211debfc3dSmrg 1221debfc3dSmrg<qandaentry xml:id="faq.how"> 1231debfc3dSmrg <question xml:id="q-how"> 1241debfc3dSmrg <para> 1251debfc3dSmrg How do I contribute to the effort? 1261debfc3dSmrg </para> 1271debfc3dSmrg </question> 1281debfc3dSmrg <answer xml:id="a-how"> 1291debfc3dSmrg <para> 1301debfc3dSmrg See the <link linkend="appendix.contrib">Contributing</link> section in 1311debfc3dSmrg the manual. Subscribing to the mailing list (see above, or 1321debfc3dSmrg the homepage) is a very good idea if you have something to 1331debfc3dSmrg contribute, or if you have spare time and want to 1341debfc3dSmrg help. Contributions don't have to be in the form of source code; 1351debfc3dSmrg anybody who is willing to help write documentation, for example, 1361debfc3dSmrg or has found a bug in code that we all thought was working and is 1371debfc3dSmrg willing to provide details, is more than welcome! 1381debfc3dSmrg </para> 1391debfc3dSmrg </answer> 1401debfc3dSmrg</qandaentry> 1411debfc3dSmrg 1421debfc3dSmrg<qandaentry xml:id="faq.whereis_old"> 1431debfc3dSmrg <question xml:id="q-whereis_old"> 1441debfc3dSmrg <para> 1451debfc3dSmrg What happened to the older libg++? I need that! 1461debfc3dSmrg </para> 1471debfc3dSmrg </question> 1481debfc3dSmrg <answer xml:id="a-whereis_old"> 1491debfc3dSmrg <para> 1501debfc3dSmrg The last libg++ README states 1511debfc3dSmrg <quote>This package is considered obsolete and is no longer 1521debfc3dSmrg being developed.</quote> 1531debfc3dSmrg It should not be used for new projects, and won't even compile with 1541debfc3dSmrg recent releases of GCC (or most other C++ compilers). 1551debfc3dSmrg </para> 1561debfc3dSmrg <para> 1571debfc3dSmrg More information can be found in the 1581debfc3dSmrg <link linkend="manual.appendix.porting.backwards">Backwards 1591debfc3dSmrg Compatibility</link> section of the libstdc++ manual. 1601debfc3dSmrg </para> 1611debfc3dSmrg </answer> 1621debfc3dSmrg</qandaentry> 1631debfc3dSmrg 1641debfc3dSmrg<qandaentry xml:id="faq.more_questions"> 1651debfc3dSmrg <question xml:id="q-more_questions"> 1661debfc3dSmrg <para> 1671debfc3dSmrg What if I have more questions? 1681debfc3dSmrg </para> 1691debfc3dSmrg </question> 1701debfc3dSmrg <answer xml:id="a-more_questions"> 1711debfc3dSmrg <para> 1721debfc3dSmrg If you have read the documentation, and your question remains 1731debfc3dSmrg unanswered, then just ask the mailing list. At present, you do not 1741debfc3dSmrg need to be subscribed to the list to send a message to it. More 1751debfc3dSmrg information is available on the homepage (including how to browse 1761debfc3dSmrg the list archives); to send a message to the list, 1771debfc3dSmrg use <email>libstdc++@gcc.gnu.org</email>. 1781debfc3dSmrg </para> 1791debfc3dSmrg 1801debfc3dSmrg <para> 1811debfc3dSmrg If you have a question that you think should be included 1821debfc3dSmrg here, or if you have a question <emphasis>about</emphasis> a question/answer 1831debfc3dSmrg here, please send email to the libstdc++ mailing list, as above. 1841debfc3dSmrg </para> 1851debfc3dSmrg </answer> 1861debfc3dSmrg</qandaentry> 1871debfc3dSmrg 1881debfc3dSmrg</qandadiv> 1891debfc3dSmrg 1901debfc3dSmrg<!-- License --> 1911debfc3dSmrg<qandadiv xml:id="faq.license" xreflabel="License QA"> 1921debfc3dSmrg 1931debfc3dSmrg 1941debfc3dSmrg<qandaentry xml:id="faq.license.what"> 1951debfc3dSmrg <question xml:id="q-license.what"> 1961debfc3dSmrg <para> 1971debfc3dSmrg What are the license terms for libstdc++? 1981debfc3dSmrg </para> 1991debfc3dSmrg </question> 2001debfc3dSmrg <answer xml:id="a-license.what"> 2011debfc3dSmrg <para> 2021debfc3dSmrg See <link linkend="manual.intro.status.license">our license description</link> 2031debfc3dSmrg for these and related questions. 2041debfc3dSmrg </para> 2051debfc3dSmrg </answer> 2061debfc3dSmrg</qandaentry> 2071debfc3dSmrg 2081debfc3dSmrg<qandaentry xml:id="faq.license.any_program"> 2091debfc3dSmrg <question xml:id="q-license.any_program"> 2101debfc3dSmrg <para> 2111debfc3dSmrg So any program which uses libstdc++ falls under the GPL? 2121debfc3dSmrg </para> 2131debfc3dSmrg </question> 2141debfc3dSmrg <answer xml:id="a-license.any_program"> 2151debfc3dSmrg <para> 2161debfc3dSmrg No. The special exception permits use of the library in 2171debfc3dSmrg proprietary applications. 2181debfc3dSmrg </para> 2191debfc3dSmrg </answer> 2201debfc3dSmrg</qandaentry> 2211debfc3dSmrg 2221debfc3dSmrg 2231debfc3dSmrg<qandaentry xml:id="faq.license.lgpl"> 2241debfc3dSmrg <question xml:id="q-license.lgpl"> 2251debfc3dSmrg <para> 2261debfc3dSmrg How is that different from the GNU {Lesser,Library} GPL? 2271debfc3dSmrg </para> 2281debfc3dSmrg </question> 2291debfc3dSmrg <answer xml:id="a-license.lgpl"> 2301debfc3dSmrg <para> 2311debfc3dSmrg The LGPL requires that users be able to replace the LGPL code with a 2321debfc3dSmrg modified version; this is trivial if the library in question is a C 2331debfc3dSmrg shared library. But there's no way to make that work with C++, where 2341debfc3dSmrg much of the library consists of inline functions and templates, which 2351debfc3dSmrg are expanded inside the code that uses the library. So to allow people 2361debfc3dSmrg to replace the library code, someone using the library would have to 2371debfc3dSmrg distribute their own source, rendering the LGPL equivalent to the GPL. 2381debfc3dSmrg </para> 2391debfc3dSmrg </answer> 2401debfc3dSmrg</qandaentry> 2411debfc3dSmrg 2421debfc3dSmrg<qandaentry xml:id="faq.license.what_restrictions"> 2431debfc3dSmrg <question xml:id="q-license.what_restrictions"> 2441debfc3dSmrg <para> 2451debfc3dSmrg I see. So, what restrictions are there on programs that use the library? 2461debfc3dSmrg </para> 2471debfc3dSmrg </question> 2481debfc3dSmrg <answer xml:id="a-license.what_restrictions"> 2491debfc3dSmrg <para> 2501debfc3dSmrg None. We encourage such programs to be released as free software, 2511debfc3dSmrg but we won't punish you or sue you if you choose otherwise. 2521debfc3dSmrg </para> 2531debfc3dSmrg </answer> 2541debfc3dSmrg</qandaentry> 2551debfc3dSmrg 2561debfc3dSmrg</qandadiv> 2571debfc3dSmrg 2581debfc3dSmrg<!-- Installation --> 2591debfc3dSmrg<qandadiv xml:id="faq.installation" xreflabel="Installation"> 2601debfc3dSmrg 2611debfc3dSmrg 2621debfc3dSmrg<qandaentry xml:id="faq.how_to_install"> 2631debfc3dSmrg <question xml:id="q-how_to_install"> 2641debfc3dSmrg <para>How do I install libstdc++? 2651debfc3dSmrg </para> 2661debfc3dSmrg </question> 2671debfc3dSmrg <answer xml:id="a-how_to_install"> 2681debfc3dSmrg <para> 2691debfc3dSmrg Often libstdc++ comes pre-installed as an integral part of many 2701debfc3dSmrg existing GNU/Linux and Unix systems, as well as many embedded 2711debfc3dSmrg development tools. It may be necessary to install extra 2721debfc3dSmrg development packages to get the headers, or the documentation, or 2731debfc3dSmrg the source: please consult your vendor for details. 2741debfc3dSmrg </para> 2751debfc3dSmrg <para> 2761debfc3dSmrg To build and install from the GNU GCC sources, please consult the 2771debfc3dSmrg <link linkend="manual.intro.setup">setup 2781debfc3dSmrg documentation</link> for detailed 2791debfc3dSmrg instructions. You may wish to browse those files ahead 2801debfc3dSmrg of time to get a feel for what's required. 2811debfc3dSmrg </para> 2821debfc3dSmrg </answer> 2831debfc3dSmrg</qandaentry> 2841debfc3dSmrg 2851debfc3dSmrg<qandaentry xml:id="faq.how_to_get_sources"> 2861debfc3dSmrg <question xml:id="q-how_to_get_sources"> 2871debfc3dSmrg <para>How does one get current libstdc++ sources? 2881debfc3dSmrg </para> 2891debfc3dSmrg </question> 2901debfc3dSmrg <answer xml:id="a-how_to_get_sources"> 2911debfc3dSmrg <para> 2921debfc3dSmrg Libstdc++ sources for all official releases can be obtained as 2931debfc3dSmrg part of the GCC sources, available from various sites and 2941debfc3dSmrg mirrors. A full <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://gcc.gnu.org/mirrors.html">list of 2951debfc3dSmrg download sites</link> is provided on the main GCC site. 2961debfc3dSmrg </para> 2971debfc3dSmrg <para> 298a2dc1f3fSmrg Current libstdc++ sources can always be found in the main GCC source 299a2dc1f3fSmrg repository, available using the appropriate version control tool. 300a2dc1f3fSmrg At this time, that tool is <application>Git</application>. 301a2dc1f3fSmrg For more details see the documentation on 302a2dc1f3fSmrg <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://gcc.gnu.org/git.html">using the Git repository</link>. 3031debfc3dSmrg </para> 3041debfc3dSmrg </answer> 3051debfc3dSmrg</qandaentry> 3061debfc3dSmrg 3071debfc3dSmrg<qandaentry xml:id="faq.how_to_test"> 3081debfc3dSmrg <question xml:id="q-how_to_test"> 3091debfc3dSmrg <para>How do I know if it works? 3101debfc3dSmrg </para> 3111debfc3dSmrg </question> 3121debfc3dSmrg <answer xml:id="a-how_to_test"> 3131debfc3dSmrg <para> 3141debfc3dSmrg Libstdc++ comes with its own validation testsuite, which includes 3151debfc3dSmrg conformance testing, regression testing, ABI testing, and 3161debfc3dSmrg performance testing. Please consult the 3171debfc3dSmrg <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/install/test.html">testing 3181debfc3dSmrg documentation</link> for GCC and 3191debfc3dSmrg <link linkend="manual.intro.setup.test">Testing</link> in the libstdc++ 3201debfc3dSmrg manual for more details. 3211debfc3dSmrg </para> 3221debfc3dSmrg <para> 3231debfc3dSmrg If you find bugs in the testsuite programs themselves, or if you 3241debfc3dSmrg think of a new test program that should be added to the suite, 3251debfc3dSmrg <emphasis>please</emphasis> write up your idea and send it to the list! 3261debfc3dSmrg </para> 3271debfc3dSmrg </answer> 3281debfc3dSmrg</qandaentry> 3291debfc3dSmrg 3301debfc3dSmrg<qandaentry xml:id="faq.how_to_set_paths"> 3311debfc3dSmrg <question xml:id="q-how_to_set_paths"> 3321debfc3dSmrg <para>How do I insure that the dynamically linked library will be found? 3331debfc3dSmrg </para> 3341debfc3dSmrg </question> 3351debfc3dSmrg <answer xml:id="a-how_to_set_paths"> 3361debfc3dSmrg <para> 3371debfc3dSmrg Depending on your platform and library version, the error message might 3381debfc3dSmrg be similar to one of the following: 3391debfc3dSmrg </para> 3401debfc3dSmrg 3411debfc3dSmrg <screen> 3421debfc3dSmrg ./a.out: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory 3431debfc3dSmrg 3441debfc3dSmrg /usr/libexec/ld-elf.so.1: Shared object "libstdc++.so.6" not found 3451debfc3dSmrg </screen> 3461debfc3dSmrg 3471debfc3dSmrg <para> 3481debfc3dSmrg This doesn't mean that the shared library isn't installed, only 3491debfc3dSmrg that the dynamic linker can't find it. When a dynamically-linked 3501debfc3dSmrg executable is run the linker finds and loads the required shared 3511debfc3dSmrg libraries by searching a pre-configured list of directories. If 3521debfc3dSmrg the directory where you've installed libstdc++ is not in this list 3531debfc3dSmrg then the libraries won't be found. 3541debfc3dSmrg </para> 3551debfc3dSmrg 3561debfc3dSmrg <para> 3571debfc3dSmrg If you already have an older version of libstdc++ installed then the 3581debfc3dSmrg error might look like one of the following instead: 3591debfc3dSmrg </para> 3601debfc3dSmrg 3611debfc3dSmrg <screen> 3621debfc3dSmrg ./a.out: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.20' not found 3631debfc3dSmrg ./a.out: /usr/lib/libstdc++.so.6: version `CXXABI_1.3.8' not found 3641debfc3dSmrg </screen> 3651debfc3dSmrg 3661debfc3dSmrg <para> 3671debfc3dSmrg This means the linker found <filename>/usr/lib/libstdc++.so.6</filename> 3681debfc3dSmrg but that library belongs to an older version of GCC than was used to 3691debfc3dSmrg compile and link the program <filename>a.out</filename> (or some part 3701debfc3dSmrg of it). The program depends on code defined in the newer libstdc++ 3711debfc3dSmrg that belongs to the newer version of GCC, so the linker must be told 3721debfc3dSmrg how to find the newer libstdc++ shared library. 3731debfc3dSmrg </para> 3741debfc3dSmrg 3751debfc3dSmrg <para> 3761debfc3dSmrg The simplest way to fix this is 3771debfc3dSmrg to use the <envar>LD_LIBRARY_PATH</envar> environment variable, 3781debfc3dSmrg which is a colon-separated list of directories in which the linker 3791debfc3dSmrg will search for shared libraries: 3801debfc3dSmrg </para> 3811debfc3dSmrg 3821debfc3dSmrg <screen><command> 3831debfc3dSmrg export LD_LIBRARY_PATH=${prefix}/lib:$LD_LIBRARY_PATH 3841debfc3dSmrg </command></screen> 3851debfc3dSmrg 3861debfc3dSmrg <para> 3871debfc3dSmrg Here the shell variable <varname>${prefix}</varname> is assumed to contain 3881debfc3dSmrg the directory prefix where GCC was installed to. The directory containing 3891debfc3dSmrg the library might depend on whether you want the 32-bit or 64-bit copy 3901debfc3dSmrg of the library, so for example would be 3911debfc3dSmrg <filename class="directory">${prefix}/lib64</filename> on some systems. 3921debfc3dSmrg The exact environment variable to use will depend on your 3931debfc3dSmrg platform, e.g. <envar>DYLD_LIBRARY_PATH</envar> for Darwin, 3941debfc3dSmrg <envar>LD_LIBRARY_PATH_32</envar>/<envar>LD_LIBRARY_PATH_64</envar> 3951debfc3dSmrg for Solaris 32-/64-bit, 3961debfc3dSmrg and <envar>SHLIB_PATH</envar> for HP-UX. 3971debfc3dSmrg </para> 3981debfc3dSmrg <para> 3991debfc3dSmrg See the man pages for <command>ld</command>, <command>ldd</command> 4001debfc3dSmrg and <command>ldconfig</command> for more information. The dynamic 4011debfc3dSmrg linker has different names on different platforms but the man page 4021debfc3dSmrg is usually called something such as <filename>ld.so</filename>, 4031debfc3dSmrg <filename>rtld</filename> or <filename>dld.so</filename>. 4041debfc3dSmrg </para> 4051debfc3dSmrg <para> 4061debfc3dSmrg Using <envar>LD_LIBRARY_PATH</envar> is not always the best solution, 4071debfc3dSmrg <link linkend="manual.intro.using.linkage.dynamic">Finding Dynamic or Shared 4081debfc3dSmrg Libraries</link> in the manual gives some alternatives. 4091debfc3dSmrg </para> 4101debfc3dSmrg </answer> 4111debfc3dSmrg</qandaentry> 4121debfc3dSmrg 4131debfc3dSmrg<qandaentry xml:id="faq.what_is_libsupcxx"> 4141debfc3dSmrg <question xml:id="q-what_is_libsupcxx"> 4151debfc3dSmrg <para> 4161debfc3dSmrg What's libsupc++? 4171debfc3dSmrg </para> 4181debfc3dSmrg </question> 4191debfc3dSmrg <answer xml:id="a-what_is_libsupcxx"> 4201debfc3dSmrg <para> 4211debfc3dSmrg If the only functions from <filename class="libraryfile">libstdc++.a</filename> 4221debfc3dSmrg which you need are language support functions (those listed in 4231debfc3dSmrg <link linkend="std.support">clause 18</link> of the 4241debfc3dSmrg standard, e.g., <function>new</function> and 4251debfc3dSmrg <function>delete</function>), then try linking against 4261debfc3dSmrg <filename class="libraryfile">libsupc++.a</filename>, which is a subset of 4271debfc3dSmrg <filename class="libraryfile">libstdc++.a</filename>. (Using <command>gcc</command> 4281debfc3dSmrg instead of <command>g++</command> and explicitly linking in 4291debfc3dSmrg <filename class="libraryfile">libsupc++.a</filename> via <option>-lsupc++</option> 4301debfc3dSmrg for the final link step will do it). This library contains only 4311debfc3dSmrg those support routines, one per object file. But if you are 4321debfc3dSmrg using anything from the rest of the library, such as IOStreams 4331debfc3dSmrg or vectors, then you'll still need pieces from 4341debfc3dSmrg <filename class="libraryfile">libstdc++.a</filename>. 4351debfc3dSmrg </para> 4361debfc3dSmrg </answer> 4371debfc3dSmrg</qandaentry> 4381debfc3dSmrg 4391debfc3dSmrg<qandaentry xml:id="faq.size"> 4401debfc3dSmrg <question xml:id="q-size"> 4411debfc3dSmrg <para> 4421debfc3dSmrg This library is HUGE! 4431debfc3dSmrg </para> 4441debfc3dSmrg </question> 4451debfc3dSmrg <answer xml:id="a-size"> 4461debfc3dSmrg <para> 4471debfc3dSmrg Usually the size of libraries on disk isn't noticeable. When a 4481debfc3dSmrg link editor (or simply <quote>linker</quote>) pulls things from a 4491debfc3dSmrg static archive library, only the necessary object files are copied 4501debfc3dSmrg into your executable, not the entire library. Unfortunately, even 4511debfc3dSmrg if you only need a single function or variable from an object file, 4521debfc3dSmrg the entire object file is extracted. (There's nothing unique to C++ 4531debfc3dSmrg or libstdc++ about this; it's just common behavior, given here 4541debfc3dSmrg for background reasons.) 4551debfc3dSmrg </para> 4561debfc3dSmrg <para> 4571debfc3dSmrg Some of the object files which make up 4581debfc3dSmrg <filename class="libraryfile">libstdc++.a</filename> are rather large. 4591debfc3dSmrg If you create a statically-linked executable with 4601debfc3dSmrg <option>-static</option>, those large object files are suddenly part 4611debfc3dSmrg of your executable. Historically the best way around this was to 4621debfc3dSmrg only place a very few functions (often only a single one) in each 4631debfc3dSmrg source/object file; then extracting a single function is the same 4641debfc3dSmrg as extracting a single <filename>.o</filename> file. For libstdc++ this 4651debfc3dSmrg is only possible to a certain extent; the object files in question contain 4661debfc3dSmrg template classes and template functions, pre-instantiated, and 4671debfc3dSmrg splitting those up causes severe maintenance headaches. 4681debfc3dSmrg </para> 4691debfc3dSmrg <para> 4701debfc3dSmrg On supported platforms, libstdc++ takes advantage of garbage 4711debfc3dSmrg collection in the GNU linker to get a result similar to separating 4721debfc3dSmrg each symbol into a separate source and object files. On these platforms, 4731debfc3dSmrg GNU ld can place each function and variable into its own 4741debfc3dSmrg section in a <filename>.o</filename> file. The GNU linker can then perform 4751debfc3dSmrg garbage collection on unused sections; this reduces the situation to only 4761debfc3dSmrg copying needed functions into the executable, as before, but all 4771debfc3dSmrg happens automatically. 4781debfc3dSmrg </para> 4791debfc3dSmrg </answer> 4801debfc3dSmrg</qandaentry> 4811debfc3dSmrg 4821debfc3dSmrg</qandadiv> 4831debfc3dSmrg 4841debfc3dSmrg 4851debfc3dSmrg<!-- Platform-Specific Issues --> 4861debfc3dSmrg<qandadiv xml:id="faq.platform-specific" xreflabel="Platform-Specific Issues"> 4871debfc3dSmrg 4881debfc3dSmrg 4891debfc3dSmrg<qandaentry xml:id="faq.other_compilers"> 4901debfc3dSmrg <question xml:id="q-other_compilers"> 4911debfc3dSmrg <para> 4921debfc3dSmrg Can libstdc++ be used with non-GNU compilers? 4931debfc3dSmrg </para> 4941debfc3dSmrg </question> 4951debfc3dSmrg <answer xml:id="a-other_compilers"> 4961debfc3dSmrg <para> 4971debfc3dSmrg Perhaps. 4981debfc3dSmrg </para> 4991debfc3dSmrg <para> 5001debfc3dSmrg Since the goal of ISO Standardization is for all C++ 5011debfc3dSmrg implementations to be able to share code, libstdc++ should be 5021debfc3dSmrg usable under any ISO-compliant compiler, at least in theory. 5031debfc3dSmrg </para> 5041debfc3dSmrg <para> 5051debfc3dSmrg However, the reality is that libstdc++ is targeted and optimized 5061debfc3dSmrg for GCC/G++. This means that often libstdc++ uses specific, 5071debfc3dSmrg non-standard features of G++ that are not present in older 5081debfc3dSmrg versions of proprietary compilers. It may take as much as a year or two 5091debfc3dSmrg after an official release of GCC that contains these features for 5101debfc3dSmrg proprietary tools to support these constructs. 5111debfc3dSmrg </para> 5121debfc3dSmrg <para> 5131debfc3dSmrg Recent versions of libstdc++ are known to work with the Clang compiler. 5141debfc3dSmrg In the near past, specific released versions of libstdc++ have 5151debfc3dSmrg been known to work with versions of the EDG C++ compiler, and 5161debfc3dSmrg vendor-specific proprietary C++ compilers such as the Intel ICC 5171debfc3dSmrg C++ compiler. 5181debfc3dSmrg </para> 5191debfc3dSmrg 5201debfc3dSmrg </answer> 5211debfc3dSmrg</qandaentry> 5221debfc3dSmrg 5231debfc3dSmrg<qandaentry xml:id="faq.solaris_long_long"> 5241debfc3dSmrg <question xml:id="q-solaris_long_long"> 5251debfc3dSmrg <para> 5261debfc3dSmrg No '<type>long long</type>' type on Solaris? 5271debfc3dSmrg </para> 5281debfc3dSmrg </question> 5291debfc3dSmrg <answer xml:id="a-solaris_long_long"> 530a2dc1f3fSmrg <note> 531a2dc1f3fSmrg <para>This answer is old and probably no longer be relevant.</para> 532a2dc1f3fSmrg </note> 5331debfc3dSmrg <para> 5341debfc3dSmrg By default we try to support the C99 <type>long long</type> type. 5351debfc3dSmrg This requires that certain functions from your C library be present. 5361debfc3dSmrg </para> 5371debfc3dSmrg <para> 5381debfc3dSmrg Up through release 3.0.2 the platform-specific tests performed by 5391debfc3dSmrg libstdc++ were too general, resulting in a conservative approach 5401debfc3dSmrg to enabling the <type>long long</type> code paths. The most 5411debfc3dSmrg commonly reported platform affected was Solaris. 5421debfc3dSmrg </para> 5431debfc3dSmrg <para> 5441debfc3dSmrg This has been fixed for libstdc++ releases greater than 3.0.3. 5451debfc3dSmrg </para> 5461debfc3dSmrg </answer> 5471debfc3dSmrg</qandaentry> 5481debfc3dSmrg 5491debfc3dSmrg<qandaentry xml:id="faq.predefined"> 5501debfc3dSmrg <question xml:id="q-predefined"> 5511debfc3dSmrg <para> 5521debfc3dSmrg <constant>_XOPEN_SOURCE</constant> and <constant>_GNU_SOURCE</constant> are always defined? 5531debfc3dSmrg </para> 5541debfc3dSmrg </question> 5551debfc3dSmrg <answer xml:id="a-predefined"> 5561debfc3dSmrg <para>On Solaris, <command>g++</command> (but not <command>gcc</command>) 5571debfc3dSmrg always defines the preprocessor macro 5581debfc3dSmrg <constant>_XOPEN_SOURCE</constant>. On GNU/Linux, the same happens 5591debfc3dSmrg with <constant>_GNU_SOURCE</constant>. (This is not an exhaustive list; 5601debfc3dSmrg other macros and other platforms are also affected.) 5611debfc3dSmrg </para> 5621debfc3dSmrg <para>These macros are typically used in C library headers, guarding new 5631debfc3dSmrg versions of functions from their older versions. The C++98 standard 5641debfc3dSmrg library includes the C standard library, but it requires the C90 5651debfc3dSmrg version, which for backwards-compatibility reasons is often not the 5661debfc3dSmrg default for many vendors. 5671debfc3dSmrg </para> 5681debfc3dSmrg <para>More to the point, the C++ standard requires behavior which is only 5691debfc3dSmrg available on certain platforms after certain symbols are defined. 5701debfc3dSmrg Usually the issue involves I/O-related typedefs. In order to 5711debfc3dSmrg ensure correctness, the compiler simply predefines those symbols. 5721debfc3dSmrg </para> 5731debfc3dSmrg <para>Note that it's not enough to <literal>#define</literal> them only when the library is 5741debfc3dSmrg being built (during installation). Since we don't have an 'export' 5751debfc3dSmrg keyword, much of the library exists as headers, which means that 5761debfc3dSmrg the symbols must also be defined as your programs are parsed and 5771debfc3dSmrg compiled. 5781debfc3dSmrg </para> 5791debfc3dSmrg <para>To see which symbols are defined, look for 5801debfc3dSmrg <varname>CPLUSPLUS_CPP_SPEC</varname> in 5811debfc3dSmrg the gcc config headers for your target (and try changing them to 5821debfc3dSmrg see what happens when building complicated code). You can also run 583*8feb0f0bSmrg <command>g++ -E -dM -x c++ /dev/null</command> to display 5841debfc3dSmrg a list of predefined macros for any particular installation. 5851debfc3dSmrg </para> 5861debfc3dSmrg <para>This has been discussed on the mailing lists 5871debfc3dSmrg <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/cgi-bin/htsearch?method=and&format=builtin-long&sort=score&words=_XOPEN_SOURCE+Solaris">quite a bit</link>. 5881debfc3dSmrg </para> 5891debfc3dSmrg <para>This method is something of a wart. We'd like to find a cleaner 5901debfc3dSmrg solution, but nobody yet has contributed the time. 5911debfc3dSmrg </para> 5921debfc3dSmrg 5931debfc3dSmrg </answer> 5941debfc3dSmrg</qandaentry> 5951debfc3dSmrg 5961debfc3dSmrg<qandaentry xml:id="faq.darwin_ctype"> 5971debfc3dSmrg <question xml:id="q-darwin_ctype"> 5981debfc3dSmrg <para> 5991debfc3dSmrg Mac OS X <filename class="headerfile">ctype.h</filename> is broken! How can I fix it? 6001debfc3dSmrg </para> 6011debfc3dSmrg </question> 6021debfc3dSmrg <answer xml:id="a-darwin_ctype"> 6031debfc3dSmrg <note> 6041debfc3dSmrg <para>This answer is old and probably no longer be relevant.</para> 6051debfc3dSmrg </note> 6061debfc3dSmrg <para> 6071debfc3dSmrg This was a long-standing bug in the OS X support. Fortunately, the 6081debfc3dSmrg <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/ml/gcc/2002-03/msg00817.html">patch</link> 6091debfc3dSmrg was quite simple, and well-known. 6101debfc3dSmrg </para> 6111debfc3dSmrg 6121debfc3dSmrg </answer> 6131debfc3dSmrg</qandaentry> 6141debfc3dSmrg 6151debfc3dSmrg<qandaentry xml:id="faq.threads_i386"> 6161debfc3dSmrg <question xml:id="q-threads_i386"> 6171debfc3dSmrg <para> 6181debfc3dSmrg Threading is broken on i386? 6191debfc3dSmrg </para> 6201debfc3dSmrg </question> 6211debfc3dSmrg <answer xml:id="a-threads_i386"> 6221debfc3dSmrg <note> 6231debfc3dSmrg <para>This answer is old and probably no longer be relevant.</para> 6241debfc3dSmrg </note> 6251debfc3dSmrg <para>Support for atomic integer operations was broken on i386 6261debfc3dSmrg platforms. The assembly code accidentally used opcodes that are 6271debfc3dSmrg only available on the i486 and later. So if you configured GCC 6281debfc3dSmrg to target, for example, i386-linux, but actually used the programs 6291debfc3dSmrg on an i686, then you would encounter no problems. Only when 6301debfc3dSmrg actually running the code on a i386 will the problem appear. 6311debfc3dSmrg </para> 6321debfc3dSmrg <para>This is fixed in 3.2.2. 6331debfc3dSmrg </para> 6341debfc3dSmrg 6351debfc3dSmrg </answer> 6361debfc3dSmrg</qandaentry> 6371debfc3dSmrg 6381debfc3dSmrg<qandaentry xml:id="faq.atomic_mips"> 6391debfc3dSmrg <question xml:id="q-atomic_mips"> 6401debfc3dSmrg <para> 6411debfc3dSmrg MIPS atomic operations 6421debfc3dSmrg </para> 6431debfc3dSmrg </question> 6441debfc3dSmrg <answer xml:id="a-atomic_mips"> 6451debfc3dSmrg <note> 6461debfc3dSmrg <para>This answer is old and probably no longer be relevant.</para> 6471debfc3dSmrg </note> 6481debfc3dSmrg <para> 6491debfc3dSmrg The atomic locking routines for MIPS targets requires MIPS II 6501debfc3dSmrg and later. A patch went in just after the 3.3 release to 6511debfc3dSmrg make mips* use the generic implementation instead. You can also 6521debfc3dSmrg configure for mipsel-elf as a workaround. 6531debfc3dSmrg </para> 6541debfc3dSmrg <para> 6551debfc3dSmrg The mips*-*-linux* port continues to use the MIPS II routines, and more 6561debfc3dSmrg work in this area is expected. 6571debfc3dSmrg </para> 6581debfc3dSmrg </answer> 6591debfc3dSmrg</qandaentry> 6601debfc3dSmrg 6611debfc3dSmrg<qandaentry xml:id="faq.linux_glibc"> 6621debfc3dSmrg <question xml:id="q-linux_glibc"> 6631debfc3dSmrg <para> 6641debfc3dSmrg Recent GNU/Linux glibc required? 6651debfc3dSmrg </para> 6661debfc3dSmrg </question> 6671debfc3dSmrg <answer xml:id="a-linux_glibc"> 6681debfc3dSmrg <para>When running on GNU/Linux, libstdc++ 3.2.1 (shared library version 6691debfc3dSmrg 5.0.1) and later uses localization and formatting code from the system 6701debfc3dSmrg C library (glibc) version 2.2.5 which contains necessary bugfixes. 6711debfc3dSmrg All GNU/Linux distros make more recent versions available now. 6721debfc3dSmrg libstdc++ 4.6.0 and later require glibc 2.3 or later for this 6731debfc3dSmrg localization and formatting code. 6741debfc3dSmrg </para> 6751debfc3dSmrg <para>The guideline is simple: the more recent the C++ library, the 6761debfc3dSmrg more recent the C library. (This is also documented in the main 6771debfc3dSmrg GCC installation instructions.) 6781debfc3dSmrg </para> 6791debfc3dSmrg 6801debfc3dSmrg </answer> 6811debfc3dSmrg</qandaentry> 6821debfc3dSmrg 6831debfc3dSmrg<qandaentry xml:id="faq.freebsd_wchar"> 6841debfc3dSmrg <question xml:id="q-freebsd_wchar"> 6851debfc3dSmrg <para> 686a2dc1f3fSmrg Can't use <type>wchar_t</type>/<classname>wstring</classname> on FreeBSD 6871debfc3dSmrg </para> 6881debfc3dSmrg </question> 6891debfc3dSmrg <answer xml:id="a-freebsd_wchar"> 6901debfc3dSmrg <note> 6911debfc3dSmrg <para>This answer is old and probably no longer be relevant.</para> 6921debfc3dSmrg </note> 6931debfc3dSmrg <para> 6941debfc3dSmrg Older versions of FreeBSD's C library do not have sufficient 6951debfc3dSmrg support for wide character functions, and as a result the 6961debfc3dSmrg libstdc++ configury decides that <type>wchar_t</type> support should be 6971debfc3dSmrg disabled. In addition, the libstdc++ platform checks that 6981debfc3dSmrg enabled <type>wchar_t</type> were quite strict, and not granular 6991debfc3dSmrg enough to detect when the minimal support to 7001debfc3dSmrg enable <type>wchar_t</type> and C++ library structures 7011debfc3dSmrg like <classname>wstring</classname> were present. This impacted Solaris, 7021debfc3dSmrg Darwin, and BSD variants, and is fixed in libstdc++ versions post 4.1.0. 7031debfc3dSmrg </para> 7041debfc3dSmrg <para> 7051debfc3dSmrg </para> 7061debfc3dSmrg </answer> 7071debfc3dSmrg</qandaentry> 7081debfc3dSmrg 7091debfc3dSmrg</qandadiv> 7101debfc3dSmrg 7111debfc3dSmrg 7121debfc3dSmrg<!-- Known Bugs --> 7131debfc3dSmrg<qandadiv xml:id="faq.known_bugs" xreflabel="Known Bugs"> 7141debfc3dSmrg 7151debfc3dSmrg 7161debfc3dSmrg<qandaentry xml:id="faq.what_works"> 7171debfc3dSmrg <question xml:id="q-what_works"> 7181debfc3dSmrg <para> 7191debfc3dSmrg What works already? 7201debfc3dSmrg </para> 7211debfc3dSmrg </question> 7221debfc3dSmrg <answer xml:id="a-what_works"> 7231debfc3dSmrg <para> 7241debfc3dSmrg Short answer: Pretty much everything <emphasis>works</emphasis> 7251debfc3dSmrg except for some corner cases. Support for localization 7261debfc3dSmrg in <classname>locale</classname> may be incomplete on some non-GNU 7271debfc3dSmrg platforms. Also dependent on the underlying platform is support 7281debfc3dSmrg for <type>wchar_t</type> and <type>long long</type> specializations, 7291debfc3dSmrg and details of thread support. 7301debfc3dSmrg </para> 7311debfc3dSmrg <para> 7321debfc3dSmrg Long answer: See the implementation status pages for 7331debfc3dSmrg <link linkend="status.iso.1998">C++98</link>, 7341debfc3dSmrg <link linkend="status.iso.tr1">TR1</link>, 7351debfc3dSmrg <link linkend="status.iso.2011">C++11</link>, 7361debfc3dSmrg <link linkend="status.iso.2014">C++14</link>, and 7371debfc3dSmrg <link linkend="status.iso.2017">C++17</link>. 7381debfc3dSmrg </para> 7391debfc3dSmrg </answer> 7401debfc3dSmrg</qandaentry> 7411debfc3dSmrg 7421debfc3dSmrg<qandaentry xml:id="faq.standard_bugs"> 7431debfc3dSmrg <question xml:id="q-standard_bugs"> 7441debfc3dSmrg <para> 7451debfc3dSmrg Bugs in the ISO C++ language or library specification 7461debfc3dSmrg </para> 7471debfc3dSmrg </question> 7481debfc3dSmrg <answer xml:id="a-standard_bugs"> 7491debfc3dSmrg <para> 7501debfc3dSmrg Unfortunately, there are some. 7511debfc3dSmrg </para> 7521debfc3dSmrg <para> 7531debfc3dSmrg For those people who are not part of the ISO Library Group 7541debfc3dSmrg (i.e., nearly all of us needing to read this page in the first 7551debfc3dSmrg place), a public list of the library defects is occasionally 7561debfc3dSmrg published on <link xmlns:xlink="http://www.w3.org/1999/xlink" 7571debfc3dSmrg xlink:href="http://www.open-std.org/jtc1/sc22/wg21/">the WG21 7581debfc3dSmrg website</link>. 759a2dc1f3fSmrg Many of these issues have resulted in 760a2dc1f3fSmrg <link linkend="manual.intro.status.bugs.iso">code changes in libstdc++</link>. 7611debfc3dSmrg </para> 7621debfc3dSmrg <para> 7631debfc3dSmrg If you think you've discovered a new bug that is not listed, 7641debfc3dSmrg please post a message describing your problem to the author of 7651debfc3dSmrg the library issues list. 7661debfc3dSmrg </para> 7671debfc3dSmrg </answer> 7681debfc3dSmrg</qandaentry> 7691debfc3dSmrg 7701debfc3dSmrg<qandaentry xml:id="faq.compiler_bugs"> 7711debfc3dSmrg <question xml:id="q-compiler_bugs"> 7721debfc3dSmrg <para> 7731debfc3dSmrg Bugs in the compiler (gcc/g++) and not libstdc++ 7741debfc3dSmrg </para> 7751debfc3dSmrg </question> 7761debfc3dSmrg <answer xml:id="a-compiler_bugs"> 7771debfc3dSmrg <para> 7781debfc3dSmrg On occasion, the compiler is wrong. Please be advised that this 7791debfc3dSmrg happens much less often than one would think, and avoid jumping to 7801debfc3dSmrg conclusions. 7811debfc3dSmrg </para> 7821debfc3dSmrg <para> 7831debfc3dSmrg First, examine the ISO C++ standard. Second, try another compiler 7841debfc3dSmrg or an older version of the GNU compilers. Third, you can find more 7851debfc3dSmrg information on the libstdc++ and the GCC mailing lists: search 7861debfc3dSmrg these lists with terms describing your issue. 7871debfc3dSmrg </para> 7881debfc3dSmrg <para> 7891debfc3dSmrg Before reporting a bug, please examine the 790a2dc1f3fSmrg <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://gcc.gnu.org/bugs/">bugs database</link>, with the 791a2dc1f3fSmrg component set to <quote>c++</quote>. 7921debfc3dSmrg </para> 7931debfc3dSmrg </answer> 7941debfc3dSmrg</qandaentry> 7951debfc3dSmrg 7961debfc3dSmrg</qandadiv> 7971debfc3dSmrg 7981debfc3dSmrg<!-- Known Non-Bugs --> 7991debfc3dSmrg<qandadiv xml:id="faq.known_non-bugs" xreflabel="Known Non-Bugs"> 8001debfc3dSmrg 8011debfc3dSmrg 8021debfc3dSmrg<qandaentry xml:id="faq.stream_reopening_fails"> 8031debfc3dSmrg <question xml:id="q-stream_reopening_fails"> 8041debfc3dSmrg <para> 8051debfc3dSmrg Reopening a stream fails 8061debfc3dSmrg </para> 8071debfc3dSmrg </question> 8081debfc3dSmrg <answer xml:id="a-stream_reopening_fails"> 809a2dc1f3fSmrg <note> 810a2dc1f3fSmrg <para>This answer is old and probably no longer be relevant.</para> 811a2dc1f3fSmrg </note> 8121debfc3dSmrg <para> 813a2dc1f3fSmrg Prior to GCC 4.0 this was one of the most-reported non-bug reports. 814a2dc1f3fSmrg Executing a sequence like this would fail: 8151debfc3dSmrg </para> 8161debfc3dSmrg 8171debfc3dSmrg <programlisting> 8181debfc3dSmrg #include <fstream> 8191debfc3dSmrg ... 8201debfc3dSmrg std::fstream fs("a_file"); 8211debfc3dSmrg // . 8221debfc3dSmrg // . do things with fs... 8231debfc3dSmrg // . 8241debfc3dSmrg fs.close(); 8251debfc3dSmrg fs.open("a_new_file"); 8261debfc3dSmrg </programlisting> 8271debfc3dSmrg 8281debfc3dSmrg <para> 829a2dc1f3fSmrg All operations on the re-opened <varname>fs</varname> would fail, or at 830a2dc1f3fSmrg least act very strangely, especially if <varname>fs</varname> reached the 831a2dc1f3fSmrg EOF state on the previous file. 832a2dc1f3fSmrg The original C++98 standard did not specify behavior in this case, and 833a2dc1f3fSmrg the <link linkend="manual.bugs.dr22">resolution of DR #22</link> was to 834a2dc1f3fSmrg leave the state flags unchanged on a successful call to 835a2dc1f3fSmrg <function>open()</function>. 836a2dc1f3fSmrg You had to insert a call to <function>fs.clear()</function> between the 837a2dc1f3fSmrg calls to <function>close()</function> and <function>open()</function>, 838a2dc1f3fSmrg and then everything will work as expected. 839a2dc1f3fSmrg <emphasis>Update:</emphasis> For GCC 4.0 we implemented the resolution 840a2dc1f3fSmrg of <link linkend="manual.bugs.dr409">DR #409</link> and 841a2dc1f3fSmrg <function>open()</function> 842a2dc1f3fSmrg now calls <function>clear()</function> on success. 8431debfc3dSmrg </para> 8441debfc3dSmrg </answer> 8451debfc3dSmrg</qandaentry> 8461debfc3dSmrg 8471debfc3dSmrg<qandaentry xml:id="faq.wefcxx_verbose"> 8481debfc3dSmrg <question xml:id="q-wefcxx_verbose"> 8491debfc3dSmrg <para> 8501debfc3dSmrg -Weffc++ complains too much 8511debfc3dSmrg </para> 8521debfc3dSmrg </question> 8531debfc3dSmrg <answer xml:id="a-wefcxx_verbose"> 8541debfc3dSmrg <para> 8551debfc3dSmrg Many warnings are emitted when <option>-Weffc++</option> is used. Making 8561debfc3dSmrg libstdc++ <option>-Weffc++</option>-clean is not a goal of the project, 8571debfc3dSmrg for a few reasons. Mainly, that option tries to enforce 8581debfc3dSmrg object-oriented programming, while the Standard Library isn't 859a2dc1f3fSmrg necessarily trying to be OO. The option also enforces outdated guidelines 860a2dc1f3fSmrg from old editions of the books, and the advice isn't all relevant to 861a2dc1f3fSmrg modern C++ (especially C++11 and later). 8621debfc3dSmrg </para> 8631debfc3dSmrg <para> 8641debfc3dSmrg We do, however, try to have libstdc++ sources as clean as possible. If 8651debfc3dSmrg you see some simple changes that pacify <option>-Weffc++</option> 8661debfc3dSmrg without other drawbacks, send us a patch. 8671debfc3dSmrg </para> 8681debfc3dSmrg </answer> 8691debfc3dSmrg</qandaentry> 8701debfc3dSmrg 8711debfc3dSmrg<qandaentry xml:id="faq.ambiguous_overloads"> 8721debfc3dSmrg <question xml:id="q-ambiguous_overloads"> 8731debfc3dSmrg <para> 8741debfc3dSmrg Ambiguous overloads after including an old-style header 8751debfc3dSmrg </para> 8761debfc3dSmrg </question> 8771debfc3dSmrg <answer xml:id="a-ambiguous_overloads"> 8781debfc3dSmrg <note> 8791debfc3dSmrg <para>This answer is old and probably no longer be relevant.</para> 8801debfc3dSmrg </note> 8811debfc3dSmrg <para> 8821debfc3dSmrg Another problem is the <literal>rel_ops</literal> namespace and the template 8831debfc3dSmrg comparison operator functions contained therein. If they become 8841debfc3dSmrg visible in the same namespace as other comparison functions 885a2dc1f3fSmrg (e.g., <quote>using</quote> them and the 886a2dc1f3fSmrg <filename class="headerfile"><iterator></filename> header), 8871debfc3dSmrg then you will suddenly be faced with huge numbers of ambiguity 888a2dc1f3fSmrg errors. This was discussed on the mailing list; Nathan Myers 8891debfc3dSmrg <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/ml/libstdc++/2001-01/msg00247.html">sums 8901debfc3dSmrg things up here</link>. The collisions with vector/string iterator 8911debfc3dSmrg types have been fixed for 3.1. 8921debfc3dSmrg </para> 8931debfc3dSmrg </answer> 8941debfc3dSmrg</qandaentry> 8951debfc3dSmrg 8961debfc3dSmrg<qandaentry xml:id="faq.v2_headers"> 8971debfc3dSmrg <question xml:id="q-v2_headers"> 8981debfc3dSmrg <para> 8991debfc3dSmrg The g++-3 headers are <emphasis>not ours</emphasis> 9001debfc3dSmrg </para> 9011debfc3dSmrg </question> 9021debfc3dSmrg <answer xml:id="a-v2_headers"> 903a2dc1f3fSmrg <note> 904a2dc1f3fSmrg <para>This answer is old and probably no longer be relevant.</para> 905a2dc1f3fSmrg </note> 9061debfc3dSmrg <para> 9071debfc3dSmrg If you are using headers in 9081debfc3dSmrg <filename class="directory">${prefix}/include/g++-3</filename>, or if 9091debfc3dSmrg the installed library's name looks like 9101debfc3dSmrg <filename class="libraryfile">libstdc++-2.10.a</filename> or 9111debfc3dSmrg <filename class="libraryfile">libstdc++-libc6-2.10.so</filename>, then 9121debfc3dSmrg you are using the old libstdc++-v2 library, which is non-standard and 9131debfc3dSmrg unmaintained. Do not report problems with -v2 to the -v3 9141debfc3dSmrg mailing list. 9151debfc3dSmrg </para> 9161debfc3dSmrg <para> 9171debfc3dSmrg For GCC versions 3.0 and 3.1 the libstdc++ header files are installed in 9181debfc3dSmrg <filename class="directory">${prefix}/include/g++-v3</filename> 9191debfc3dSmrg (see the 'v'?). Starting with version 3.2 the headers are installed in 9201debfc3dSmrg <filename class="directory">${prefix}/include/c++/${version}</filename> 9211debfc3dSmrg as this prevents headers from previous versions being found by mistake. 9221debfc3dSmrg </para> 9231debfc3dSmrg 9241debfc3dSmrg </answer> 9251debfc3dSmrg</qandaentry> 9261debfc3dSmrg 9271debfc3dSmrg<qandaentry xml:id="faq.boost_concept_checks"> 9281debfc3dSmrg <question xml:id="q-boost_concept_checks"> 9291debfc3dSmrg <para> 9301debfc3dSmrg Errors about <emphasis>*Concept</emphasis> and 9311debfc3dSmrg <emphasis>constraints</emphasis> in the STL 9321debfc3dSmrg </para> 9331debfc3dSmrg </question> 9341debfc3dSmrg <answer xml:id="a-boost_concept_checks"> 9351debfc3dSmrg <para> 9361debfc3dSmrg If you see compilation errors containing messages about 9371debfc3dSmrg <errortext>foo Concept</errortext> and something to do with a 9381debfc3dSmrg <errortext>constraints</errortext> member function, then most 9391debfc3dSmrg likely you have violated one of the requirements for types used 9401debfc3dSmrg during instantiation of template containers and functions. For 9411debfc3dSmrg example, EqualityComparableConcept appears if your types must be 9421debfc3dSmrg comparable with == and you have not provided this capability (a 9431debfc3dSmrg typo, or wrong visibility, or you just plain forgot, etc). 9441debfc3dSmrg </para> 9451debfc3dSmrg <para> 9461debfc3dSmrg More information, including how to optionally enable/disable the 9471debfc3dSmrg checks, is available in the 9481debfc3dSmrg <link linkend="std.diagnostics.concept_checking">Diagnostics</link>. 9491debfc3dSmrg chapter of the manual. 9501debfc3dSmrg </para> 9511debfc3dSmrg </answer> 9521debfc3dSmrg</qandaentry> 9531debfc3dSmrg 9541debfc3dSmrg<qandaentry xml:id="faq.dlopen_crash"> 9551debfc3dSmrg <question xml:id="q-dlopen_crash"> 9561debfc3dSmrg <para> 9571debfc3dSmrg Program crashes when using library code in a 9581debfc3dSmrg dynamically-loaded library 9591debfc3dSmrg </para> 9601debfc3dSmrg </question> 9611debfc3dSmrg <answer xml:id="a-dlopen_crash"> 9621debfc3dSmrg <para> 9631debfc3dSmrg If you are using the C++ library across dynamically-loaded 9641debfc3dSmrg objects, make certain that you are passing the correct options 9651debfc3dSmrg when compiling and linking: 9661debfc3dSmrg </para> 9671debfc3dSmrg 9681debfc3dSmrg <literallayout class="normal"> 9691debfc3dSmrg Compile your library components: 9701debfc3dSmrg <command>g++ -fPIC -c a.cc</command> 9711debfc3dSmrg <command>g++ -fPIC -c b.cc</command> 9721debfc3dSmrg ... 9731debfc3dSmrg <command>g++ -fPIC -c z.cc</command> 9741debfc3dSmrg 9751debfc3dSmrg Create your library: 9761debfc3dSmrg <command>g++ -fPIC -shared -rdynamic -o libfoo.so a.o b.o ... z.o</command> 9771debfc3dSmrg 9781debfc3dSmrg Link the executable: 9791debfc3dSmrg <command>g++ -fPIC -rdynamic -o foo ... -L. -lfoo -ldl</command> 9801debfc3dSmrg </literallayout> 9811debfc3dSmrg </answer> 9821debfc3dSmrg</qandaentry> 9831debfc3dSmrg 9841debfc3dSmrg<qandaentry xml:id="faq.memory_leaks"> 9851debfc3dSmrg <question xml:id="q-memory_leaks"> 9861debfc3dSmrg <para> 987a2dc1f3fSmrg <quote>Memory leaks</quote> in libstdc++ 9881debfc3dSmrg </para> 9891debfc3dSmrg </question> 9901debfc3dSmrg <answer xml:id="a-memory_leaks"> 9911debfc3dSmrg <para> 992a2dc1f3fSmrg Since GCC 5.1.0, libstdc++ automatically allocates a pool 993a2dc1f3fSmrg of a few dozen kilobytes on startup. This pool is used to ensure it's 994a2dc1f3fSmrg possible to throw exceptions (such as <classname>bad_alloc</classname>) 995a2dc1f3fSmrg even when <code>malloc</code> is unable to allocate any more memory. 996a2dc1f3fSmrg With some versions of <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://valgrind.org/"><command>valgrind</command></link> 997a2dc1f3fSmrg this pool will be shown as "still reachable" when the process exits, e.g. 998a2dc1f3fSmrg <code>still reachable: 72,704 bytes in 1 blocks</code>. 999a2dc1f3fSmrg This memory is not a leak, because it's still in use by libstdc++, 1000a2dc1f3fSmrg and the memory will be returned to the OS when the process exits. 1001a2dc1f3fSmrg Later versions of <command>valgrind</command> know how to free this 1002a2dc1f3fSmrg pool as the process exits, and so won't show any "still reachable" memory. 1003a2dc1f3fSmrg </para> 1004a2dc1f3fSmrg <para> 1005a2dc1f3fSmrg In the past, a few people reported that the standard containers appear 10061debfc3dSmrg to leak memory when tested with memory checkers such as 10071debfc3dSmrg <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://valgrind.org/"><command>valgrind</command></link>. 1008a2dc1f3fSmrg Under some (non-default) configurations the library's allocators keep 1009a2dc1f3fSmrg free memory in a 1010a2dc1f3fSmrg pool for later reuse, rather than deallocating it with <code>delete</code> 1011a2dc1f3fSmrg Although this memory is always reachable by the library and is never 10121debfc3dSmrg lost, memory debugging tools can report it as a leak. If you 10131debfc3dSmrg want to test the library for memory leaks please read 10141debfc3dSmrg <link linkend="debug.memory">Tips for memory leak hunting</link> 10151debfc3dSmrg first. 10161debfc3dSmrg </para> 10171debfc3dSmrg </answer> 10181debfc3dSmrg</qandaentry> 10191debfc3dSmrg 10201debfc3dSmrg<qandaentry xml:id="faq.list_size_on"> 10211debfc3dSmrg <question xml:id="q-list_size_on"> 10221debfc3dSmrg <para> 1023a2dc1f3fSmrg <code>list::size()</code> is O(n)! 10241debfc3dSmrg </para> 10251debfc3dSmrg </question> 10261debfc3dSmrg <answer xml:id="a-list_size_on"> 10271debfc3dSmrg <para> 10281debfc3dSmrg See 10291debfc3dSmrg the <link linkend="std.containers">Containers</link> 10301debfc3dSmrg chapter. 10311debfc3dSmrg </para> 10321debfc3dSmrg </answer> 10331debfc3dSmrg</qandaentry> 10341debfc3dSmrg 10351debfc3dSmrg<qandaentry xml:id="faq.easy_to_fix"> 10361debfc3dSmrg <question xml:id="q-easy_to_fix"> 10371debfc3dSmrg <para> 10381debfc3dSmrg Aw, that's easy to fix! 10391debfc3dSmrg </para> 10401debfc3dSmrg </question> 10411debfc3dSmrg <answer xml:id="a-easy_to_fix"> 10421debfc3dSmrg <para> 10431debfc3dSmrg If you have found a bug in the library and you think you have 10441debfc3dSmrg a working fix, then send it in! The main GCC site has a page 10451debfc3dSmrg on <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/contribute.html">submitting 10461debfc3dSmrg patches</link> that covers the procedure, but for libstdc++ you 10471debfc3dSmrg should also send the patch to our mailing list in addition to 10481debfc3dSmrg the GCC patches mailing list. The libstdc++ 10491debfc3dSmrg <link linkend="appendix.contrib">contributors' page</link> 10501debfc3dSmrg also talks about how to submit patches. 10511debfc3dSmrg </para> 10521debfc3dSmrg <para> 10531debfc3dSmrg In addition to the description, the patch, and the ChangeLog 10541debfc3dSmrg entry, it is a Good Thing if you can additionally create a small 10551debfc3dSmrg test program to test for the presence of the bug that your patch 10561debfc3dSmrg fixes. Bugs have a way of being reintroduced; if an old bug 10571debfc3dSmrg creeps back in, it will be caught immediately by the testsuite - 10581debfc3dSmrg but only if such a test exists. 10591debfc3dSmrg </para> 10601debfc3dSmrg </answer> 10611debfc3dSmrg</qandaentry> 10621debfc3dSmrg 10631debfc3dSmrg</qandadiv> 10641debfc3dSmrg 10651debfc3dSmrg 10661debfc3dSmrg<!-- Miscellaneous --> 10671debfc3dSmrg<qandadiv xml:id="faq.misc" xreflabel="Miscellaneous"> 10681debfc3dSmrg 10691debfc3dSmrg 10701debfc3dSmrg<qandaentry xml:id="faq.iterator_as_pod"> 10711debfc3dSmrg <question xml:id="faq.iterator_as_pod_q"> 10721debfc3dSmrg <para> 1073a2dc1f3fSmrg <classname>string::iterator</classname> is not <code>char*</code>; 1074a2dc1f3fSmrg <classname>vector<T>::iterator</classname> is not <code>T*</code> 10751debfc3dSmrg </para> 10761debfc3dSmrg </question> 10771debfc3dSmrg <answer xml:id="faq.iterator_as_pod_a"> 10781debfc3dSmrg <para> 10791debfc3dSmrg If you have code that depends on container<T> iterators 10801debfc3dSmrg being implemented as pointer-to-T, your code is broken. It's 10811debfc3dSmrg considered a feature, not a bug, that libstdc++ points this out. 10821debfc3dSmrg </para> 10831debfc3dSmrg <para> 10841debfc3dSmrg While there are arguments for iterators to be implemented in 10851debfc3dSmrg that manner, A) they aren't very good ones in the long term, 10861debfc3dSmrg and B) they were never guaranteed by the Standard anyway. The 10871debfc3dSmrg type-safety achieved by making iterators a real class rather 10881debfc3dSmrg than a typedef for <type>T*</type> outweighs nearly all opposing 10891debfc3dSmrg arguments. 10901debfc3dSmrg </para> 10911debfc3dSmrg <para> 1092a2dc1f3fSmrg Code which does assume that a vector/string iterator <varname>i</varname> 10931debfc3dSmrg is a pointer can often be fixed by changing <varname>i</varname> in 1094a2dc1f3fSmrg certain expressions to <varname>&*i</varname>. 10951debfc3dSmrg </para> 10961debfc3dSmrg </answer> 10971debfc3dSmrg</qandaentry> 10981debfc3dSmrg 10991debfc3dSmrg<qandaentry xml:id="faq.what_is_next"> 11001debfc3dSmrg <question xml:id="q-what_is_next"> 11011debfc3dSmrg <para> 11021debfc3dSmrg What's next after libstdc++? 11031debfc3dSmrg </para> 11041debfc3dSmrg </question> 11051debfc3dSmrg <answer xml:id="a-what_is_next"> 11061debfc3dSmrg <para> 1107a2dc1f3fSmrg The goal of libstdc++ is to produce a 1108a2dc1f3fSmrg fully-compliant, fully-portable Standard Library. 1109a2dc1f3fSmrg While the C++ Standard continues to evolve the libstdc++ will 1110a2dc1f3fSmrg continue to track it. 11111debfc3dSmrg </para> 11121debfc3dSmrg </answer> 11131debfc3dSmrg</qandaentry> 11141debfc3dSmrg 11151debfc3dSmrg<qandaentry xml:id="faq.sgi_stl"> 11161debfc3dSmrg <question xml:id="q-sgi_stl"> 11171debfc3dSmrg <para> 11181debfc3dSmrg What about the STL from SGI? 11191debfc3dSmrg </para> 11201debfc3dSmrg </question> 11211debfc3dSmrg <answer xml:id="a-sgi_stl"> 11221debfc3dSmrg <para> 1123a2dc1f3fSmrg The STL (Standard Template Library) was the inspiration for large chunks 1124a2dc1f3fSmrg of the C++ Standard Library, but the terms are not interchangeable and 1125a2dc1f3fSmrg they don't mean the same thing. The C++ Standard Library includes lots of 1126a2dc1f3fSmrg things that didn't come from the STL, and some of them aren't even 1127a2dc1f3fSmrg templates, such as <classname>std::locale</classname> and 1128a2dc1f3fSmrg <classname>std::thread</classname>. 1129a2dc1f3fSmrg </para> 1130a2dc1f3fSmrg <para> 1131a2dc1f3fSmrg Libstdc++-v3 incorporates a lot of code from 1132a2dc1f3fSmrg <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://web.archive.org/web/20171225062613/http://www.sgi.com/tech/stl/">the SGI STL</link> 1133a2dc1f3fSmrg (the final merge was from 1134a2dc1f3fSmrg <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://web.archive.org/web/20171225062613/http://www.sgi.com/tech/stl/whats_new.html">release 3.3</link>). 1135a2dc1f3fSmrg The code in libstdc++ contains many fixes and changes compared to the 1136a2dc1f3fSmrg original SGI code. 11371debfc3dSmrg </para> 11381debfc3dSmrg <para> 11391debfc3dSmrg In particular, <classname>string</classname> is not from SGI and makes no 1140a2dc1f3fSmrg use of their "rope" class (although that is included as an optional 1141a2dc1f3fSmrg extension), neither is <classname>valarray</classname> nor some others. 1142a2dc1f3fSmrg Classes like <classname>vector<></classname> were from SGI, but have 1143a2dc1f3fSmrg been extensively modified. 11441debfc3dSmrg </para> 11451debfc3dSmrg <para> 11461debfc3dSmrg More information on the evolution of libstdc++ can be found at the 11471debfc3dSmrg <link linkend="appendix.porting.api">API 11481debfc3dSmrg evolution</link> 11491debfc3dSmrg and <link linkend="manual.appendix.porting.backwards">backwards 11501debfc3dSmrg compatibility</link> documentation. 11511debfc3dSmrg </para> 11521debfc3dSmrg <para> 1153*8feb0f0bSmrg The <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://web.archive.org/web/20171104092813/http://www.sgi.com/tech/stl/FAQ.html">FAQ</link> 11541debfc3dSmrg for SGI's STL is still recommended reading. 11551debfc3dSmrg </para> 11561debfc3dSmrg </answer> 11571debfc3dSmrg</qandaentry> 11581debfc3dSmrg 11591debfc3dSmrg<qandaentry xml:id="faq.extensions_and_backwards_compat"> 11601debfc3dSmrg <question xml:id="q-extensions_and_backwards_compat"> 11611debfc3dSmrg <para> 11621debfc3dSmrg Extensions and Backward Compatibility 11631debfc3dSmrg </para> 11641debfc3dSmrg </question> 11651debfc3dSmrg <answer xml:id="a-extensions_and_backwards_compat"> 11661debfc3dSmrg <para> 11671debfc3dSmrg See the <link linkend="manual.appendix.porting.backwards">link</link> on backwards compatibility and <link linkend="appendix.porting.api">link</link> on evolution. 11681debfc3dSmrg </para> 11691debfc3dSmrg </answer> 11701debfc3dSmrg</qandaentry> 11711debfc3dSmrg 11721debfc3dSmrg<qandaentry xml:id="faq.tr1_support"> 11731debfc3dSmrg <question xml:id="q-tr1_support"> 11741debfc3dSmrg <para> 11751debfc3dSmrg Does libstdc++ support TR1? 11761debfc3dSmrg </para> 11771debfc3dSmrg </question> 11781debfc3dSmrg <answer xml:id="a-tr1_support"> 11791debfc3dSmrg <para> 11801debfc3dSmrg Yes. 11811debfc3dSmrg </para> 11821debfc3dSmrg <para> 1183a2dc1f3fSmrg The C++ Standard Library 11841debfc3dSmrg <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1836.pdf"> 1185a2dc1f3fSmrg Technical Report 1</link> added many new features to the library. 11861debfc3dSmrg </para> 11871debfc3dSmrg <para> 1188a2dc1f3fSmrg The implementation status of TR1 in libstdc++ can be tracked 1189a2dc1f3fSmrg <link linkend="status.iso.tr1">on the TR1 status page</link>. 1190a2dc1f3fSmrg </para> 1191a2dc1f3fSmrg <para> 1192a2dc1f3fSmrg New code should probably not use TR1, because almost everything in it has 1193a2dc1f3fSmrg been added to the main C++ Standard Library (usually with significant 1194a2dc1f3fSmrg improvements). 1195a2dc1f3fSmrg The TR1 implementation in libstdc++ is no longer actively maintained. 11961debfc3dSmrg </para> 11971debfc3dSmrg </answer> 11981debfc3dSmrg</qandaentry> 11991debfc3dSmrg 12001debfc3dSmrg<qandaentry xml:id="faq.get_iso_cxx"> 12011debfc3dSmrg <question xml:id="q-get_iso_cxx"> 12021debfc3dSmrg <para>How do I get a copy of the ISO C++ Standard? 12031debfc3dSmrg </para> 12041debfc3dSmrg </question> 12051debfc3dSmrg <answer xml:id="a-get_iso_cxx"> 12061debfc3dSmrg <para> 12071debfc3dSmrg Please refer to the <link linkend="appendix.contrib">Contributing</link> 12081debfc3dSmrg section in our manual. 12091debfc3dSmrg </para> 12101debfc3dSmrg </answer> 12111debfc3dSmrg</qandaentry> 12121debfc3dSmrg 12131debfc3dSmrg<qandaentry xml:id="faq.what_is_abi"> 12141debfc3dSmrg <question xml:id="q-what_is_abi"> 12151debfc3dSmrg <para> 12161debfc3dSmrg What's an ABI and why is it so messy? 12171debfc3dSmrg </para> 12181debfc3dSmrg </question> 12191debfc3dSmrg <answer xml:id="a-what_is_abi"> 12201debfc3dSmrg <para> 12211debfc3dSmrg <acronym>ABI</acronym> stands for <quote>Application Binary 12221debfc3dSmrg Interface</quote>. Conventionally, it refers to a great 12231debfc3dSmrg mass of details about how arguments are arranged on the call 12241debfc3dSmrg stack and/or in registers, and how various types are arranged 12251debfc3dSmrg and padded in structs. A single CPU design may suffer 12261debfc3dSmrg multiple ABIs designed by different development tool vendors 12271debfc3dSmrg who made different choices, or even by the same vendor for 12281debfc3dSmrg different target applications or compiler versions. In ideal 12291debfc3dSmrg circumstances the CPU designer presents one ABI and all the 12301debfc3dSmrg OSes and compilers use it. In practice every ABI omits 12311debfc3dSmrg details that compiler implementers (consciously or 12321debfc3dSmrg accidentally) must choose for themselves. 12331debfc3dSmrg </para> 12341debfc3dSmrg <para> 12351debfc3dSmrg That ABI definition suffices for compilers to generate code so a 12361debfc3dSmrg program can interact safely with an OS and its lowest-level libraries. 12371debfc3dSmrg Users usually want an ABI to encompass more detail, allowing libraries 12381debfc3dSmrg built with different compilers (or different releases of the same 12391debfc3dSmrg compiler!) to be linked together. For C++, this includes many more 12401debfc3dSmrg details than for C, and most CPU designers (for good reasons elaborated 12411debfc3dSmrg below) have not stepped up to publish C++ ABIs. Such an ABI has been 12421debfc3dSmrg defined for the Itanium architecture (see 12431debfc3dSmrg <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://itanium-cxx-abi.github.io/cxx-abi/">C++ 12441debfc3dSmrg ABI for Itanium</link>) and that is used by G++ and other compilers 12451debfc3dSmrg as the de facto standard ABI on many common architectures (including x86). 12461debfc3dSmrg G++ can also use the ARM architecture's EABI, for embedded 12471debfc3dSmrg systems relying only on a <quote>free-standing implementation</quote> that 12481debfc3dSmrg doesn't include (much of) the standard library, and the GNU EABI for 12491debfc3dSmrg hosted implementations on ARM. Those ABIs cover low-level details 12501debfc3dSmrg such as virtual function implementation, struct inheritance layout, 12511debfc3dSmrg name mangling, and exception handling. 12521debfc3dSmrg </para> 12531debfc3dSmrg <para> 12541debfc3dSmrg A useful C++ ABI must also incorporate many details of the standard 12551debfc3dSmrg library implementation. For a C ABI, the layouts of a few structs 12561debfc3dSmrg (such as <type>FILE</type>, <type>stat</type>, <type>jmpbuf</type>, 12571debfc3dSmrg and the like) and a few macros suffice. 12581debfc3dSmrg For C++, the details include the complete set of names of functions 12591debfc3dSmrg and types used, the offsets of class members and virtual functions, 12601debfc3dSmrg and the actual definitions of all inlines. C++ exposes many more 12611debfc3dSmrg library details to the caller than C does. It makes defining 12621debfc3dSmrg a complete ABI a much bigger undertaking, and requires not just 12631debfc3dSmrg documenting library implementation details, but carefully designing 12641debfc3dSmrg those details so that future bug fixes and optimizations don't 12651debfc3dSmrg force breaking the ABI. 12661debfc3dSmrg </para> 12671debfc3dSmrg <para> 12681debfc3dSmrg There are ways to help isolate library implementation details from the 12691debfc3dSmrg ABI, but they trade off against speed. Library details used in inner 12701debfc3dSmrg loops (e.g., <function>getchar</function>) must be exposed and frozen for 12711debfc3dSmrg all time, but many others may reasonably be kept hidden from user code, 12721debfc3dSmrg so they may later be changed. Deciding which, and implementing 12731debfc3dSmrg the decisions, must happen before you can reasonably document a 12741debfc3dSmrg candidate C++ ABI that encompasses the standard library. 12751debfc3dSmrg </para> 12761debfc3dSmrg </answer> 12771debfc3dSmrg</qandaentry> 12781debfc3dSmrg 12791debfc3dSmrg<qandaentry xml:id="faq.size_equals_capacity"> 12801debfc3dSmrg <question xml:id="q-size_equals_capacity"> 12811debfc3dSmrg <para> 1282a2dc1f3fSmrg How do I make <code>std::vector<T>::capacity() == std::vector<T>::size</code>? 12831debfc3dSmrg </para> 12841debfc3dSmrg </question> 12851debfc3dSmrg <answer xml:id="a-size_equals_capacity"> 12861debfc3dSmrg <para> 1287a2dc1f3fSmrg Since C++11 just call the <function>shrink_to_fit()</function> member 1288a2dc1f3fSmrg function. 1289a2dc1f3fSmrg </para> 1290a2dc1f3fSmrg <para> 1291a2dc1f3fSmrg Before C++11, the standard idiom for deallocating a 1292a2dc1f3fSmrg <classname>vector<T></classname>'s 1293a2dc1f3fSmrg unused memory was to create a temporary copy of the vector and swap their 12941debfc3dSmrg contents, e.g. for <classname>vector<T> v</classname> 12951debfc3dSmrg </para> 12961debfc3dSmrg <literallayout class="normal"> 12971debfc3dSmrg std::vector<T>(v).swap(v); 12981debfc3dSmrg </literallayout> 12991debfc3dSmrg <para> 13001debfc3dSmrg The copy will take O(n) time and the swap is constant time. 13011debfc3dSmrg </para> 13021debfc3dSmrg <para> 13031debfc3dSmrg See <link linkend="strings.string.shrink">Shrink-to-fit 13041debfc3dSmrg strings</link> for a similar solution for strings. 13051debfc3dSmrg </para> 13061debfc3dSmrg </answer> 13071debfc3dSmrg</qandaentry> 13081debfc3dSmrg 13091debfc3dSmrg</qandadiv> 13101debfc3dSmrg 13111debfc3dSmrg 13121debfc3dSmrg<!-- FAQ ends here --> 13131debfc3dSmrg</qandaset> 13141debfc3dSmrg 13151debfc3dSmrg</article> 13161debfc3dSmrg 13171debfc3dSmrg</book> 1318