11debfc3dSmrg<appendix xmlns="http://docbook.org/ns/docbook" version="5.0" 21debfc3dSmrg xml:id="appendix.contrib" xreflabel="Contributing"> 31debfc3dSmrg<?dbhtml filename="appendix_contributing.html"?> 41debfc3dSmrg 51debfc3dSmrg<info><title> 61debfc3dSmrg Contributing 71debfc3dSmrg <indexterm> 81debfc3dSmrg <primary>Appendix</primary> 91debfc3dSmrg <secondary>Contributing</secondary> 101debfc3dSmrg </indexterm> 111debfc3dSmrg</title> 121debfc3dSmrg <keywordset> 131debfc3dSmrg <keyword>ISO C++</keyword> 141debfc3dSmrg <keyword>library</keyword> 151debfc3dSmrg </keywordset> 161debfc3dSmrg</info> 171debfc3dSmrg 181debfc3dSmrg 191debfc3dSmrg 201debfc3dSmrg<para> 211debfc3dSmrg The GNU C++ Library is part of GCC and follows the same development model, 221debfc3dSmrg so the general rules for 231debfc3dSmrg <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/contribute.html">contributing 241debfc3dSmrg to GCC</link> apply. Active 251debfc3dSmrg contributors are assigned maintainership responsibility, and given 261debfc3dSmrg write access to the source repository. First-time contributors 271debfc3dSmrg should follow this procedure: 281debfc3dSmrg</para> 291debfc3dSmrg 301debfc3dSmrg<section xml:id="contrib.list" xreflabel="Contributor Checklist"><info><title>Contributor Checklist</title></info> 311debfc3dSmrg 321debfc3dSmrg 331debfc3dSmrg <section xml:id="list.reading"><info><title>Reading</title></info> 341debfc3dSmrg 351debfc3dSmrg 361debfc3dSmrg <itemizedlist> 371debfc3dSmrg <listitem> 381debfc3dSmrg <para> 391debfc3dSmrg Get and read the relevant sections of the C++ language 401debfc3dSmrg specification. Copies of the full ISO 14882 standard are 411debfc3dSmrg available on line via the ISO mirror site for committee 421debfc3dSmrg members. Non-members, or those who have not paid for the 431debfc3dSmrg privilege of sitting on the committee and sustained their 441debfc3dSmrg two meeting commitment for voting rights, may get a copy of 451debfc3dSmrg the standard from their respective national standards 461debfc3dSmrg organization. In the USA, this national standards 471debfc3dSmrg organization is 481debfc3dSmrg <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://www.ansi.org">ANSI</link>. 491debfc3dSmrg (And if you've already registered with them you can <link 501debfc3dSmrg xmlns:xlink="http://www.w3.org/1999/xlink" 51*8feb0f0bSmrg xlink:href="https://webstore.ansi.org/Standards/ISO/ISOIEC148822014">buy 521debfc3dSmrg the standard on-line</link>.) 531debfc3dSmrg </para> 541debfc3dSmrg </listitem> 551debfc3dSmrg 561debfc3dSmrg <listitem> 571debfc3dSmrg <para> 581debfc3dSmrg The library working group bugs, and known defects, can 591debfc3dSmrg be obtained here: 601debfc3dSmrg <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.open-std.org/jtc1/sc22/wg21/">http://www.open-std.org/jtc1/sc22/wg21</link> 611debfc3dSmrg </para> 621debfc3dSmrg </listitem> 631debfc3dSmrg 641debfc3dSmrg <listitem> 651debfc3dSmrg <para> 661debfc3dSmrg Peruse 671debfc3dSmrg the <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.gnu.org/prep/standards/">GNU 681debfc3dSmrg Coding Standards</link>, and chuckle when you hit the part 691debfc3dSmrg about <quote>Using Languages Other Than C</quote>. 701debfc3dSmrg </para> 711debfc3dSmrg </listitem> 721debfc3dSmrg 731debfc3dSmrg <listitem> 741debfc3dSmrg <para> 751debfc3dSmrg Be familiar with the extensions that preceded these 761debfc3dSmrg general GNU rules. These style issues for libstdc++ can be 771debfc3dSmrg found in <link linkend="contrib.coding_style">Coding Style</link>. 781debfc3dSmrg </para> 791debfc3dSmrg </listitem> 801debfc3dSmrg 811debfc3dSmrg <listitem> 821debfc3dSmrg <para> 831debfc3dSmrg And last but certainly not least, read the 841debfc3dSmrg library-specific information found in 851debfc3dSmrg <link linkend="appendix.porting">Porting and Maintenance</link>. 861debfc3dSmrg </para> 871debfc3dSmrg </listitem> 881debfc3dSmrg </itemizedlist> 891debfc3dSmrg 901debfc3dSmrg </section> 911debfc3dSmrg <section xml:id="list.copyright"><info><title>Assignment</title></info> 921debfc3dSmrg 931debfc3dSmrg <para> 941debfc3dSmrg See the <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/contribute.html#legal">legal prerequisites</link> for all GCC contributions. 951debfc3dSmrg </para> 961debfc3dSmrg 971debfc3dSmrg <para> 981debfc3dSmrg Historically, the libstdc++ assignment form added the following 991debfc3dSmrg question: 1001debfc3dSmrg </para> 1011debfc3dSmrg 1021debfc3dSmrg <para> 1031debfc3dSmrg <quote> 1041debfc3dSmrg Which Belgian comic book character is better, Tintin or Asterix, and 1051debfc3dSmrg why? 1061debfc3dSmrg </quote> 1071debfc3dSmrg </para> 1081debfc3dSmrg 1091debfc3dSmrg <para> 1101debfc3dSmrg While not strictly necessary, humoring the maintainers and answering 1111debfc3dSmrg this question would be appreciated. 1121debfc3dSmrg </para> 1131debfc3dSmrg 1141debfc3dSmrg <para> 1151debfc3dSmrg Please contact 1161debfc3dSmrg Paolo Carlini at <email>paolo.carlini@oracle.com</email> 1171debfc3dSmrg or 1181debfc3dSmrg Jonathan Wakely at <email>jwakely+assign@redhat.com</email> 1191debfc3dSmrg if you are confused about the assignment or have general licensing 1201debfc3dSmrg questions. When requesting an assignment form from 1211debfc3dSmrg <email>assign@gnu.org</email>, please CC the libstdc++ 1221debfc3dSmrg maintainers above so that progress can be monitored. 1231debfc3dSmrg </para> 1241debfc3dSmrg </section> 1251debfc3dSmrg 1261debfc3dSmrg <section xml:id="list.getting"><info><title>Getting Sources</title></info> 1271debfc3dSmrg 1281debfc3dSmrg <para> 129*8feb0f0bSmrg <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://gcc.gnu.org/gitwrite.html">Getting write access 1301debfc3dSmrg (look for "Write after approval")</link> 1311debfc3dSmrg </para> 1321debfc3dSmrg </section> 1331debfc3dSmrg 1341debfc3dSmrg <section xml:id="list.patches"><info><title>Submitting Patches</title></info> 1351debfc3dSmrg 1361debfc3dSmrg 1371debfc3dSmrg <para> 1381debfc3dSmrg Every patch must have several pieces of information before it can be 1391debfc3dSmrg properly evaluated. Ideally (and to ensure the fastest possible 1401debfc3dSmrg response from the maintainers) it would have all of these pieces: 1411debfc3dSmrg </para> 1421debfc3dSmrg 1431debfc3dSmrg <itemizedlist> 1441debfc3dSmrg <listitem> 1451debfc3dSmrg <para> 1461debfc3dSmrg A description of the bug and how your patch fixes this 1471debfc3dSmrg bug. For new features a description of the feature and your 1481debfc3dSmrg implementation. 1491debfc3dSmrg </para> 1501debfc3dSmrg </listitem> 1511debfc3dSmrg 1521debfc3dSmrg <listitem> 1531debfc3dSmrg <para> 1541debfc3dSmrg A ChangeLog entry as plain text; see the various 1551debfc3dSmrg ChangeLog files for format and content. If you are 1561debfc3dSmrg using emacs as your editor, simply position the insertion 1571debfc3dSmrg point at the beginning of your change and hit CX-4a to bring 1581debfc3dSmrg up the appropriate ChangeLog entry. See--magic! Similar 1591debfc3dSmrg functionality also exists for vi. 1601debfc3dSmrg </para> 1611debfc3dSmrg </listitem> 1621debfc3dSmrg 1631debfc3dSmrg <listitem> 1641debfc3dSmrg <para> 1651debfc3dSmrg A testsuite submission or sample program that will 1661debfc3dSmrg easily and simply show the existing error or test new 1671debfc3dSmrg functionality. 1681debfc3dSmrg </para> 1691debfc3dSmrg </listitem> 1701debfc3dSmrg 1711debfc3dSmrg <listitem> 1721debfc3dSmrg <para> 173a2dc1f3fSmrg The patch itself. If you are using the Git repository use 174a2dc1f3fSmrg <command>git diff</command> or <command>git format-patch</command> 175a2dc1f3fSmrg to produce a patch; 176a2dc1f3fSmrg otherwise, use <command>diff -cp OLD NEW</command>. If your 1771debfc3dSmrg version of diff does not support these options, then get the 178a2dc1f3fSmrg latest version of GNU diff. 1791debfc3dSmrg </para> 1801debfc3dSmrg </listitem> 1811debfc3dSmrg 1821debfc3dSmrg <listitem> 1831debfc3dSmrg <para> 1841debfc3dSmrg When you have all these pieces, bundle them up in a 1851debfc3dSmrg mail message and send it to libstdc++@gcc.gnu.org. All 1861debfc3dSmrg patches and related discussion should be sent to the 1871debfc3dSmrg libstdc++ mailing list. In common with the rest of GCC, 1881debfc3dSmrg patches should also be sent to the gcc-patches mailing list. 1891debfc3dSmrg </para> 1901debfc3dSmrg </listitem> 1911debfc3dSmrg </itemizedlist> 1921debfc3dSmrg 1931debfc3dSmrg </section> 1941debfc3dSmrg 1951debfc3dSmrg</section> 1961debfc3dSmrg 1971debfc3dSmrg<section xml:id="contrib.organization" xreflabel="Source Organization"><info><title>Directory Layout and Source Conventions</title></info> 1981debfc3dSmrg <?dbhtml filename="source_organization.html"?> 1991debfc3dSmrg 2001debfc3dSmrg 2011debfc3dSmrg <para> 2021debfc3dSmrg The <filename class="directory">libstdc++-v3</filename> directory in the 2031debfc3dSmrg GCC sources contains the files needed to create the GNU C++ Library. 2041debfc3dSmrg </para> 2051debfc3dSmrg 2061debfc3dSmrg<para> 2071debfc3dSmrgIt has subdirectories: 2081debfc3dSmrg</para> 2091debfc3dSmrg 2101debfc3dSmrg<variablelist> 2111debfc3dSmrg <varlistentry> 2121debfc3dSmrg <term><filename class="directory">doc</filename></term> 2131debfc3dSmrg <listitem> 2141debfc3dSmrg Files in HTML and text format that document usage, quirks of the 2151debfc3dSmrg implementation, and contributor checklists. 2161debfc3dSmrg </listitem> 2171debfc3dSmrg </varlistentry> 2181debfc3dSmrg 2191debfc3dSmrg <varlistentry> 2201debfc3dSmrg <term><filename class="directory">include</filename></term> 2211debfc3dSmrg <listitem> 2221debfc3dSmrg All header files for the C++ library are within this directory, 2231debfc3dSmrg modulo specific runtime-related files that are in the libsupc++ 2241debfc3dSmrg directory. 2251debfc3dSmrg 2261debfc3dSmrg <variablelist> 2271debfc3dSmrg <varlistentry> 2281debfc3dSmrg <term><filename class="directory">include/std</filename></term> 2291debfc3dSmrg <listitem> 2301debfc3dSmrg Files meant to be found by <code>#include <name></code> directives 2311debfc3dSmrg in standard-conforming user programs. 2321debfc3dSmrg </listitem> 2331debfc3dSmrg </varlistentry> 2341debfc3dSmrg 2351debfc3dSmrg <varlistentry> 2361debfc3dSmrg <term><filename class="directory">include/c</filename></term> 2371debfc3dSmrg <listitem> 2381debfc3dSmrg Headers intended to directly include standard C headers. 2391debfc3dSmrg [NB: this can be enabled via <option>--enable-cheaders=c</option>] 2401debfc3dSmrg </listitem> 2411debfc3dSmrg </varlistentry> 2421debfc3dSmrg 2431debfc3dSmrg <varlistentry> 2441debfc3dSmrg <term><filename class="directory">include/c_global</filename></term> 2451debfc3dSmrg <listitem> 2461debfc3dSmrg Headers intended to include standard C headers in 2471debfc3dSmrg the global namespace, and put select names into the <code>std::</code> 2481debfc3dSmrg namespace. [NB: this is the default, and is the same as 2491debfc3dSmrg <option>--enable-cheaders=c_global</option>] 2501debfc3dSmrg </listitem> 2511debfc3dSmrg </varlistentry> 2521debfc3dSmrg 2531debfc3dSmrg <varlistentry> 2541debfc3dSmrg <term><filename class="directory">include/c_std</filename></term> 2551debfc3dSmrg <listitem> 2561debfc3dSmrg Headers intended to include standard C headers 2571debfc3dSmrg already in namespace std, and put select names into the <code>std::</code> 2581debfc3dSmrg namespace. [NB: this is the same as 2591debfc3dSmrg <option>--enable-cheaders=c_std</option>] 2601debfc3dSmrg </listitem> 2611debfc3dSmrg </varlistentry> 2621debfc3dSmrg 2631debfc3dSmrg <varlistentry> 2641debfc3dSmrg <term><filename class="directory">include/bits</filename></term> 2651debfc3dSmrg <listitem> 2661debfc3dSmrg Files included by standard headers and by other files in 2671debfc3dSmrg the bits directory. 2681debfc3dSmrg </listitem> 2691debfc3dSmrg </varlistentry> 2701debfc3dSmrg 2711debfc3dSmrg <varlistentry> 2721debfc3dSmrg <term><filename class="directory">include/backward</filename></term> 2731debfc3dSmrg <listitem> 2741debfc3dSmrg Headers provided for backward compatibility, such as 2751debfc3dSmrg <filename class="headerfile"><backward/hash_map></filename>. 2761debfc3dSmrg They are not used in this library. 2771debfc3dSmrg </listitem> 2781debfc3dSmrg </varlistentry> 2791debfc3dSmrg 2801debfc3dSmrg <varlistentry> 2811debfc3dSmrg <term><filename class="directory">include/ext</filename></term> 2821debfc3dSmrg <listitem> 2831debfc3dSmrg Headers that define extensions to the standard library. No 2841debfc3dSmrg standard header refers to any of them, in theory (there are some 2851debfc3dSmrg exceptions). 2861debfc3dSmrg </listitem> 2871debfc3dSmrg </varlistentry> 2881debfc3dSmrg 2891debfc3dSmrg <varlistentry> 2901debfc3dSmrg <term> 2911debfc3dSmrg <filename class="directory">include/debug</filename>, 2921debfc3dSmrg <filename class="directory">include/parallel</filename>, and 2931debfc3dSmrg </term> 2941debfc3dSmrg <listitem> 295*8feb0f0bSmrg Headers that implement the Debug Mode and Parallel Mode extensions. 2961debfc3dSmrg </listitem> 2971debfc3dSmrg </varlistentry> 2981debfc3dSmrg </variablelist> 2991debfc3dSmrg </listitem> 3001debfc3dSmrg </varlistentry> 3011debfc3dSmrg 3021debfc3dSmrg <varlistentry> 3031debfc3dSmrg <term><filename class="directory">scripts</filename></term> 3041debfc3dSmrg <listitem> 3051debfc3dSmrg Scripts that are used during the configure, build, make, or test 3061debfc3dSmrg process. 3071debfc3dSmrg </listitem> 3081debfc3dSmrg </varlistentry> 3091debfc3dSmrg 3101debfc3dSmrg <varlistentry> 3111debfc3dSmrg <term><filename class="directory">src</filename></term> 3121debfc3dSmrg <listitem> 3131debfc3dSmrg Files that are used in constructing the library, but are not 3141debfc3dSmrg installed. 3151debfc3dSmrg 3161debfc3dSmrg <variablelist> 3171debfc3dSmrg <varlistentry> 3181debfc3dSmrg <term><filename class="directory">src/c++98</filename></term> 3191debfc3dSmrg <listitem> 3201debfc3dSmrg Source files compiled using <option>-std=gnu++98</option>. 3211debfc3dSmrg </listitem> 3221debfc3dSmrg </varlistentry> 3231debfc3dSmrg 3241debfc3dSmrg <varlistentry> 3251debfc3dSmrg <term><filename class="directory">src/c++11</filename></term> 3261debfc3dSmrg <listitem> 3271debfc3dSmrg Source files compiled using <option>-std=gnu++11</option>. 3281debfc3dSmrg </listitem> 3291debfc3dSmrg </varlistentry> 3301debfc3dSmrg 3311debfc3dSmrg <varlistentry> 3321debfc3dSmrg <term><filename class="directory">src/filesystem</filename></term> 3331debfc3dSmrg <listitem> 3341debfc3dSmrg Source files for the Filesystem TS. 3351debfc3dSmrg </listitem> 3361debfc3dSmrg </varlistentry> 3371debfc3dSmrg 3381debfc3dSmrg <varlistentry> 3391debfc3dSmrg <term><filename class="directory">src/shared</filename></term> 3401debfc3dSmrg <listitem> 3411debfc3dSmrg Source code included by other files under both 3421debfc3dSmrg <filename class="directory">src/c++98</filename> and 3431debfc3dSmrg <filename class="directory">src/c++11</filename> 3441debfc3dSmrg </listitem> 3451debfc3dSmrg </varlistentry> 3461debfc3dSmrg </variablelist> 3471debfc3dSmrg </listitem> 3481debfc3dSmrg </varlistentry> 3491debfc3dSmrg 3501debfc3dSmrg <varlistentry> 3511debfc3dSmrg <term><filename class="directory">testsuites/[backward, demangle, ext, performance, thread, 17_* to 30_*]</filename></term> 3521debfc3dSmrg <listitem> 3531debfc3dSmrg Test programs are here, and may be used to begin to exercise the 3541debfc3dSmrg library. Support for "make check" and "make check-install" is 3551debfc3dSmrg complete, and runs through all the subdirectories here when this 3561debfc3dSmrg command is issued from the build directory. Please note that 3571debfc3dSmrg "make check" requires DejaGnu 1.4 or later to be installed, 3581debfc3dSmrg or for extra <link linkend="test.run.permutations">permutations</link> 3591debfc3dSmrg DejaGnu 1.5.3 or later. 3601debfc3dSmrg </listitem> 3611debfc3dSmrg </varlistentry> 3621debfc3dSmrg</variablelist> 3631debfc3dSmrg 3641debfc3dSmrg<para> 3651debfc3dSmrgOther subdirectories contain variant versions of certain files 3661debfc3dSmrgthat are meant to be copied or linked by the configure script. 3671debfc3dSmrgCurrently these are: 3681debfc3dSmrg<literallayout><filename class="directory">config/abi</filename> 3691debfc3dSmrg<filename class="directory">config/allocator</filename> 3701debfc3dSmrg<filename class="directory">config/cpu</filename> 3711debfc3dSmrg<filename class="directory">config/io</filename> 3721debfc3dSmrg<filename class="directory">config/locale</filename> 3731debfc3dSmrg<filename class="directory">config/os</filename> 3741debfc3dSmrg</literallayout> 3751debfc3dSmrg</para> 3761debfc3dSmrg 3771debfc3dSmrg<para> 3781debfc3dSmrgIn addition, a subdirectory holds the convenience library libsupc++. 3791debfc3dSmrg</para> 3801debfc3dSmrg 3811debfc3dSmrg<variablelist> 3821debfc3dSmrg<varlistentry> 3831debfc3dSmrg <term><filename class="directory">libsupc++</filename></term> 3841debfc3dSmrg <listitem> 3851debfc3dSmrg Contains the runtime library for C++, including exception 3861debfc3dSmrg handling and memory allocation and deallocation, RTTI, terminate 3871debfc3dSmrg handlers, etc. 3881debfc3dSmrg </listitem> 3891debfc3dSmrg</varlistentry> 3901debfc3dSmrg</variablelist> 3911debfc3dSmrg 3921debfc3dSmrg<para> 3931debfc3dSmrgNote that glibc also has a <filename class="directory">bits/</filename> 3941debfc3dSmrgsubdirectory. We need to be careful not to collide with names in its 3951debfc3dSmrg<filename class="directory">bits/</filename> directory. For example 3961debfc3dSmrg<filename class="headerfile"><bits/std_mutex.h></filename> has to be 3971debfc3dSmrgrenamed from <filename class="headerfile"><bits/mutex.h></filename>. 3981debfc3dSmrgAnother solution would be to rename <filename class="directory">bits</filename> 3991debfc3dSmrgto (e.g.) <filename class="directory">cppbits</filename>. 4001debfc3dSmrg</para> 4011debfc3dSmrg 4021debfc3dSmrg<para> 4031debfc3dSmrgIn files throughout the system, lines marked with an "XXX" indicate 4041debfc3dSmrga bug or incompletely-implemented feature. Lines marked "XXX MT" 4051debfc3dSmrgindicate a place that may require attention for multi-thread safety. 4061debfc3dSmrg</para> 4071debfc3dSmrg 4081debfc3dSmrg</section> 4091debfc3dSmrg 4101debfc3dSmrg<section xml:id="contrib.coding_style" xreflabel="Coding Style"><info><title>Coding Style</title></info> 4111debfc3dSmrg <?dbhtml filename="source_code_style.html"?> 4121debfc3dSmrg 4131debfc3dSmrg <para> 4141debfc3dSmrg </para> 415*8feb0f0bSmrg 416*8feb0f0bSmrg <section xml:id="coding_style.bad_identifiers"><info><title>Bad Identifiers</title></info> <!-- BADNAMES --> 4171debfc3dSmrg 4181debfc3dSmrg <para> 4191debfc3dSmrg Identifiers that conflict and should be avoided. 4201debfc3dSmrg </para> 4211debfc3dSmrg 4221debfc3dSmrg <literallayout class="normal"> 4231debfc3dSmrg This is the list of names <quote>reserved to the 4241debfc3dSmrg implementation</quote> that have been claimed by certain 4251debfc3dSmrg compilers and system headers of interest, and should not be used 4261debfc3dSmrg in the library. It will grow, of course. We generally are 4271debfc3dSmrg interested in names that are not all-caps, except for those like 4281debfc3dSmrg "_T" 4291debfc3dSmrg 4301debfc3dSmrg For Solaris: 4311debfc3dSmrg _B 4321debfc3dSmrg _C 4331debfc3dSmrg _L 4341debfc3dSmrg _N 4351debfc3dSmrg _P 4361debfc3dSmrg _S 4371debfc3dSmrg _U 4381debfc3dSmrg _X 4391debfc3dSmrg _E1 4401debfc3dSmrg .. 4411debfc3dSmrg _E24 4421debfc3dSmrg 4431debfc3dSmrg Irix adds: 4441debfc3dSmrg _A 4451debfc3dSmrg _G 4461debfc3dSmrg 4471debfc3dSmrg MS adds: 4481debfc3dSmrg _T 449*8feb0f0bSmrg __deref 4501debfc3dSmrg 4511debfc3dSmrg BSD adds: 4521debfc3dSmrg __used 4531debfc3dSmrg __unused 4541debfc3dSmrg __inline 4551debfc3dSmrg _Complex 4561debfc3dSmrg __istype 4571debfc3dSmrg __maskrune 4581debfc3dSmrg __tolower 4591debfc3dSmrg __toupper 4601debfc3dSmrg __wchar_t 4611debfc3dSmrg __wint_t 4621debfc3dSmrg _res 4631debfc3dSmrg _res_ext 4641debfc3dSmrg __tg_* 4651debfc3dSmrg 466*8feb0f0bSmrg VxWorks adds: 467*8feb0f0bSmrg _C2 4681debfc3dSmrg 4691debfc3dSmrg For GCC: 4701debfc3dSmrg 4711debfc3dSmrg [Note that this list is out of date. It applies to the old 4721debfc3dSmrg name-mangling; in G++ 3.0 and higher a different name-mangling is 4731debfc3dSmrg used. In addition, many of the bugs relating to G++ interpreting 4741debfc3dSmrg these names as operators have been fixed.] 4751debfc3dSmrg 4761debfc3dSmrg The full set of __* identifiers (combined from gcc/cp/lex.c and 4771debfc3dSmrg gcc/cplus-dem.c) that are either old or new, but are definitely 4781debfc3dSmrg recognized by the demangler, is: 4791debfc3dSmrg 4801debfc3dSmrg __aa 4811debfc3dSmrg __aad 4821debfc3dSmrg __ad 4831debfc3dSmrg __addr 4841debfc3dSmrg __adv 4851debfc3dSmrg __aer 4861debfc3dSmrg __als 4871debfc3dSmrg __alshift 4881debfc3dSmrg __amd 4891debfc3dSmrg __ami 4901debfc3dSmrg __aml 4911debfc3dSmrg __amu 4921debfc3dSmrg __aor 4931debfc3dSmrg __apl 4941debfc3dSmrg __array 4951debfc3dSmrg __ars 4961debfc3dSmrg __arshift 4971debfc3dSmrg __as 4981debfc3dSmrg __bit_and 4991debfc3dSmrg __bit_ior 5001debfc3dSmrg __bit_not 5011debfc3dSmrg __bit_xor 5021debfc3dSmrg __call 5031debfc3dSmrg __cl 5041debfc3dSmrg __cm 5051debfc3dSmrg __cn 5061debfc3dSmrg __co 5071debfc3dSmrg __component 5081debfc3dSmrg __compound 5091debfc3dSmrg __cond 5101debfc3dSmrg __convert 5111debfc3dSmrg __delete 5121debfc3dSmrg __dl 5131debfc3dSmrg __dv 5141debfc3dSmrg __eq 5151debfc3dSmrg __er 5161debfc3dSmrg __ge 5171debfc3dSmrg __gt 5181debfc3dSmrg __indirect 5191debfc3dSmrg __le 5201debfc3dSmrg __ls 5211debfc3dSmrg __lt 5221debfc3dSmrg __max 5231debfc3dSmrg __md 5241debfc3dSmrg __method_call 5251debfc3dSmrg __mi 5261debfc3dSmrg __min 5271debfc3dSmrg __minus 5281debfc3dSmrg __ml 5291debfc3dSmrg __mm 5301debfc3dSmrg __mn 5311debfc3dSmrg __mult 5321debfc3dSmrg __mx 5331debfc3dSmrg __ne 5341debfc3dSmrg __negate 5351debfc3dSmrg __new 5361debfc3dSmrg __nop 5371debfc3dSmrg __nt 5381debfc3dSmrg __nw 5391debfc3dSmrg __oo 5401debfc3dSmrg __op 5411debfc3dSmrg __or 5421debfc3dSmrg __pl 5431debfc3dSmrg __plus 5441debfc3dSmrg __postdecrement 5451debfc3dSmrg __postincrement 5461debfc3dSmrg __pp 5471debfc3dSmrg __pt 5481debfc3dSmrg __rf 5491debfc3dSmrg __rm 5501debfc3dSmrg __rs 5511debfc3dSmrg __sz 5521debfc3dSmrg __trunc_div 5531debfc3dSmrg __trunc_mod 5541debfc3dSmrg __truth_andif 5551debfc3dSmrg __truth_not 5561debfc3dSmrg __truth_orif 5571debfc3dSmrg __vc 5581debfc3dSmrg __vd 5591debfc3dSmrg __vn 5601debfc3dSmrg 5611debfc3dSmrg SGI badnames: 5621debfc3dSmrg __builtin_alloca 5631debfc3dSmrg __builtin_fsqrt 5641debfc3dSmrg __builtin_sqrt 5651debfc3dSmrg __builtin_fabs 5661debfc3dSmrg __builtin_dabs 5671debfc3dSmrg __builtin_cast_f2i 5681debfc3dSmrg __builtin_cast_i2f 5691debfc3dSmrg __builtin_cast_d2ll 5701debfc3dSmrg __builtin_cast_ll2d 5711debfc3dSmrg __builtin_copy_dhi2i 5721debfc3dSmrg __builtin_copy_i2dhi 5731debfc3dSmrg __builtin_copy_dlo2i 5741debfc3dSmrg __builtin_copy_i2dlo 5751debfc3dSmrg __add_and_fetch 5761debfc3dSmrg __sub_and_fetch 5771debfc3dSmrg __or_and_fetch 5781debfc3dSmrg __xor_and_fetch 5791debfc3dSmrg __and_and_fetch 5801debfc3dSmrg __nand_and_fetch 5811debfc3dSmrg __mpy_and_fetch 5821debfc3dSmrg __min_and_fetch 5831debfc3dSmrg __max_and_fetch 5841debfc3dSmrg __fetch_and_add 5851debfc3dSmrg __fetch_and_sub 5861debfc3dSmrg __fetch_and_or 5871debfc3dSmrg __fetch_and_xor 5881debfc3dSmrg __fetch_and_and 5891debfc3dSmrg __fetch_and_nand 5901debfc3dSmrg __fetch_and_mpy 5911debfc3dSmrg __fetch_and_min 5921debfc3dSmrg __fetch_and_max 5931debfc3dSmrg __lock_test_and_set 5941debfc3dSmrg __lock_release 5951debfc3dSmrg __lock_acquire 5961debfc3dSmrg __compare_and_swap 5971debfc3dSmrg __synchronize 5981debfc3dSmrg __high_multiply 5991debfc3dSmrg __unix 6001debfc3dSmrg __sgi 6011debfc3dSmrg __linux__ 6021debfc3dSmrg __i386__ 6031debfc3dSmrg __i486__ 6041debfc3dSmrg __cplusplus 6051debfc3dSmrg __embedded_cplusplus 6061debfc3dSmrg // long double conversion members mangled as __opr 6071debfc3dSmrg // http://gcc.gnu.org/ml/libstdc++/1999-q4/msg00060.html 6081debfc3dSmrg __opr 6091debfc3dSmrg </literallayout> 6101debfc3dSmrg </section> 6111debfc3dSmrg 6121debfc3dSmrg <section xml:id="coding_style.example"><info><title>By Example</title></info> 6131debfc3dSmrg 6141debfc3dSmrg <literallayout class="normal"> 6151debfc3dSmrg This library is written to appropriate C++ coding standards. As such, 6161debfc3dSmrg it is intended to precede the recommendations of the GNU Coding 6171debfc3dSmrg Standard, which can be referenced in full here: 6181debfc3dSmrg 6191debfc3dSmrg <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.gnu.org/prep/standards/standards.html#Formatting">http://www.gnu.org/prep/standards/standards.html#Formatting</link> 6201debfc3dSmrg 6211debfc3dSmrg The rest of this is also interesting reading, but skip the "Design 6221debfc3dSmrg Advice" part. 6231debfc3dSmrg 6241debfc3dSmrg The GCC coding conventions are here, and are also useful: 6251debfc3dSmrg <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/codingconventions.html">http://gcc.gnu.org/codingconventions.html</link> 6261debfc3dSmrg 6271debfc3dSmrg In addition, because it doesn't seem to be stated explicitly anywhere 6281debfc3dSmrg else, there is an 80 column source limit. 6291debfc3dSmrg 6301debfc3dSmrg <filename>ChangeLog</filename> entries for member functions should use the 6311debfc3dSmrg classname::member function name syntax as follows: 6321debfc3dSmrg 6331debfc3dSmrg<code> 6341debfc3dSmrg1999-04-15 Dennis Ritchie <dr@att.com> 6351debfc3dSmrg 6361debfc3dSmrg * src/basic_file.cc (__basic_file::open): Fix thinko in 6371debfc3dSmrg _G_HAVE_IO_FILE_OPEN bits. 6381debfc3dSmrg</code> 6391debfc3dSmrg 6401debfc3dSmrg Notable areas of divergence from what may be previous local practice 6411debfc3dSmrg (particularly for GNU C) include: 6421debfc3dSmrg 6431debfc3dSmrg 01. Pointers and references 6441debfc3dSmrg <code> 6451debfc3dSmrg char* p = "flop"; 6461debfc3dSmrg char& c = *p; 6471debfc3dSmrg -NOT- 6481debfc3dSmrg char *p = "flop"; // wrong 6491debfc3dSmrg char &c = *p; // wrong 6501debfc3dSmrg </code> 6511debfc3dSmrg 6521debfc3dSmrg Reason: In C++, definitions are mixed with executable code. Here, 6531debfc3dSmrg <code>p</code> is being initialized, not <code>*p</code>. This is near-universal 6541debfc3dSmrg practice among C++ programmers; it is normal for C hackers 6551debfc3dSmrg to switch spontaneously as they gain experience. 6561debfc3dSmrg 6571debfc3dSmrg 02. Operator names and parentheses 6581debfc3dSmrg <code> 6591debfc3dSmrg operator==(type) 6601debfc3dSmrg -NOT- 6611debfc3dSmrg operator == (type) // wrong 6621debfc3dSmrg </code> 6631debfc3dSmrg 6641debfc3dSmrg Reason: The <code>==</code> is part of the function name. Separating 6651debfc3dSmrg it makes the declaration look like an expression. 6661debfc3dSmrg 6671debfc3dSmrg 03. Function names and parentheses 6681debfc3dSmrg <code> 6691debfc3dSmrg void mangle() 6701debfc3dSmrg -NOT- 6711debfc3dSmrg void mangle () // wrong 6721debfc3dSmrg </code> 6731debfc3dSmrg 6741debfc3dSmrg Reason: no space before parentheses (except after a control-flow 6751debfc3dSmrg keyword) is near-universal practice for C++. It identifies the 6761debfc3dSmrg parentheses as the function-call operator or declarator, as 6771debfc3dSmrg opposed to an expression or other overloaded use of parentheses. 6781debfc3dSmrg 6791debfc3dSmrg 04. Template function indentation 6801debfc3dSmrg <code> 6811debfc3dSmrg template<typename T> 6821debfc3dSmrg void 6831debfc3dSmrg template_function(args) 6841debfc3dSmrg { } 6851debfc3dSmrg -NOT- 6861debfc3dSmrg template<class T> 6871debfc3dSmrg void template_function(args) {}; 6881debfc3dSmrg </code> 6891debfc3dSmrg 6901debfc3dSmrg Reason: In class definitions, without indentation whitespace is 6911debfc3dSmrg needed both above and below the declaration to distinguish 6921debfc3dSmrg it visually from other members. (Also, re: "typename" 6931debfc3dSmrg rather than "class".) <code>T</code> often could be <code>int</code>, which is 6941debfc3dSmrg not a class. ("class", here, is an anachronism.) 6951debfc3dSmrg 6961debfc3dSmrg 05. Template class indentation 6971debfc3dSmrg <code> 6981debfc3dSmrg template<typename _CharT, typename _Traits> 6991debfc3dSmrg class basic_ios : public ios_base 7001debfc3dSmrg { 7011debfc3dSmrg public: 7021debfc3dSmrg // Types: 7031debfc3dSmrg }; 7041debfc3dSmrg -NOT- 7051debfc3dSmrg template<class _CharT, class _Traits> 7061debfc3dSmrg class basic_ios : public ios_base 7071debfc3dSmrg { 7081debfc3dSmrg public: 7091debfc3dSmrg // Types: 7101debfc3dSmrg }; 7111debfc3dSmrg -NOT- 7121debfc3dSmrg template<class _CharT, class _Traits> 7131debfc3dSmrg class basic_ios : public ios_base 7141debfc3dSmrg { 7151debfc3dSmrg public: 7161debfc3dSmrg // Types: 7171debfc3dSmrg }; 7181debfc3dSmrg </code> 7191debfc3dSmrg 7201debfc3dSmrg 06. Enumerators 7211debfc3dSmrg <code> 7221debfc3dSmrg enum 7231debfc3dSmrg { 7241debfc3dSmrg space = _ISspace, 7251debfc3dSmrg print = _ISprint, 7261debfc3dSmrg cntrl = _IScntrl 7271debfc3dSmrg }; 7281debfc3dSmrg -NOT- 7291debfc3dSmrg enum { space = _ISspace, print = _ISprint, cntrl = _IScntrl }; 7301debfc3dSmrg </code> 7311debfc3dSmrg 7321debfc3dSmrg 07. Member initialization lists 7331debfc3dSmrg All one line, separate from class name. 7341debfc3dSmrg 7351debfc3dSmrg <code> 7361debfc3dSmrg gribble::gribble() 7371debfc3dSmrg : _M_private_data(0), _M_more_stuff(0), _M_helper(0) 7381debfc3dSmrg { } 7391debfc3dSmrg -NOT- 7401debfc3dSmrg gribble::gribble() : _M_private_data(0), _M_more_stuff(0), _M_helper(0) 7411debfc3dSmrg { } 7421debfc3dSmrg </code> 7431debfc3dSmrg 7441debfc3dSmrg 08. Try/Catch blocks 7451debfc3dSmrg <code> 7461debfc3dSmrg try 7471debfc3dSmrg { 7481debfc3dSmrg // 7491debfc3dSmrg } 7501debfc3dSmrg catch (...) 7511debfc3dSmrg { 7521debfc3dSmrg // 7531debfc3dSmrg } 7541debfc3dSmrg -NOT- 7551debfc3dSmrg try { 7561debfc3dSmrg // 7571debfc3dSmrg } catch(...) { 7581debfc3dSmrg // 7591debfc3dSmrg } 7601debfc3dSmrg </code> 7611debfc3dSmrg 7621debfc3dSmrg 09. Member functions declarations and definitions 7631debfc3dSmrg Keywords such as extern, static, export, explicit, inline, etc 7641debfc3dSmrg go on the line above the function name. Thus 7651debfc3dSmrg 7661debfc3dSmrg <code> 7671debfc3dSmrg virtual int 7681debfc3dSmrg foo() 7691debfc3dSmrg -NOT- 7701debfc3dSmrg virtual int foo() 7711debfc3dSmrg </code> 7721debfc3dSmrg 7731debfc3dSmrg Reason: GNU coding conventions dictate return types for functions 7741debfc3dSmrg are on a separate line than the function name and parameter list 7751debfc3dSmrg for definitions. For C++, where we have member functions that can 7761debfc3dSmrg be either inline definitions or declarations, keeping to this 7771debfc3dSmrg standard allows all member function names for a given class to be 7781debfc3dSmrg aligned to the same margin, increasing readability. 7791debfc3dSmrg 7801debfc3dSmrg 7811debfc3dSmrg 10. Invocation of member functions with "this->" 7821debfc3dSmrg For non-uglified names, use <code>this->name</code> to call the function. 7831debfc3dSmrg 7841debfc3dSmrg <code> 7851debfc3dSmrg this->sync() 7861debfc3dSmrg -NOT- 7871debfc3dSmrg sync() 7881debfc3dSmrg </code> 7891debfc3dSmrg 7901debfc3dSmrg Reason: Koenig lookup. 7911debfc3dSmrg 7921debfc3dSmrg 11. Namespaces 7931debfc3dSmrg <code> 7941debfc3dSmrg namespace std 7951debfc3dSmrg { 7961debfc3dSmrg blah blah blah; 7971debfc3dSmrg } // namespace std 7981debfc3dSmrg 7991debfc3dSmrg -NOT- 8001debfc3dSmrg 8011debfc3dSmrg namespace std { 8021debfc3dSmrg blah blah blah; 8031debfc3dSmrg } // namespace std 8041debfc3dSmrg </code> 8051debfc3dSmrg 8061debfc3dSmrg 12. Spacing under protected and private in class declarations: 8071debfc3dSmrg space above, none below 8081debfc3dSmrg i.e. 8091debfc3dSmrg 8101debfc3dSmrg <code> 8111debfc3dSmrg public: 8121debfc3dSmrg int foo; 8131debfc3dSmrg 8141debfc3dSmrg -NOT- 8151debfc3dSmrg public: 8161debfc3dSmrg 8171debfc3dSmrg int foo; 8181debfc3dSmrg </code> 8191debfc3dSmrg 8201debfc3dSmrg 13. Spacing WRT return statements. 8211debfc3dSmrg no extra spacing before returns, no parenthesis 8221debfc3dSmrg i.e. 8231debfc3dSmrg 8241debfc3dSmrg <code> 8251debfc3dSmrg } 8261debfc3dSmrg return __ret; 8271debfc3dSmrg 8281debfc3dSmrg -NOT- 8291debfc3dSmrg } 8301debfc3dSmrg 8311debfc3dSmrg return __ret; 8321debfc3dSmrg 8331debfc3dSmrg -NOT- 8341debfc3dSmrg 8351debfc3dSmrg } 8361debfc3dSmrg return (__ret); 8371debfc3dSmrg </code> 8381debfc3dSmrg 8391debfc3dSmrg 8401debfc3dSmrg 14. Location of global variables. 8411debfc3dSmrg All global variables of class type, whether in the "user visible" 8421debfc3dSmrg space (e.g., <code>cin</code>) or the implementation namespace, must be defined 8431debfc3dSmrg as a character array with the appropriate alignment and then later 8441debfc3dSmrg re-initialized to the correct value. 8451debfc3dSmrg 8461debfc3dSmrg This is due to startup issues on certain platforms, such as AIX. 8471debfc3dSmrg For more explanation and examples, see <filename>src/globals.cc</filename>. All such 8481debfc3dSmrg variables should be contained in that file, for simplicity. 8491debfc3dSmrg 8501debfc3dSmrg 15. Exception abstractions 8511debfc3dSmrg Use the exception abstractions found in <filename class="headerfile">functexcept.h</filename>, which allow 8521debfc3dSmrg C++ programmers to use this library with <literal>-fno-exceptions</literal>. (Even if 8531debfc3dSmrg that is rarely advisable, it's a necessary evil for backwards 8541debfc3dSmrg compatibility.) 8551debfc3dSmrg 8561debfc3dSmrg 16. Exception error messages 8571debfc3dSmrg All start with the name of the function where the exception is 8581debfc3dSmrg thrown, and then (optional) descriptive text is added. Example: 8591debfc3dSmrg 8601debfc3dSmrg <code> 8611debfc3dSmrg __throw_logic_error(__N("basic_string::_S_construct NULL not valid")); 8621debfc3dSmrg </code> 8631debfc3dSmrg 8641debfc3dSmrg Reason: The verbose terminate handler prints out <code>exception::what()</code>, 8651debfc3dSmrg as well as the typeinfo for the thrown exception. As this is the 8661debfc3dSmrg default terminate handler, by putting location info into the 8671debfc3dSmrg exception string, a very useful error message is printed out for 8681debfc3dSmrg uncaught exceptions. So useful, in fact, that non-programmers can 8691debfc3dSmrg give useful error messages, and programmers can intelligently 8701debfc3dSmrg speculate what went wrong without even using a debugger. 8711debfc3dSmrg 8721debfc3dSmrg 17. The doxygen style guide to comments is a separate document, 8731debfc3dSmrg see index. 8741debfc3dSmrg 8751debfc3dSmrg The library currently has a mixture of GNU-C and modern C++ coding 8761debfc3dSmrg styles. The GNU C usages will be combed out gradually. 8771debfc3dSmrg 8781debfc3dSmrg Name patterns: 8791debfc3dSmrg 8801debfc3dSmrg For nonstandard names appearing in Standard headers, we are constrained 8811debfc3dSmrg to use names that begin with underscores. This is called "uglification". 8821debfc3dSmrg The convention is: 8831debfc3dSmrg 8841debfc3dSmrg Local and argument names: <literal>__[a-z].*</literal> 8851debfc3dSmrg 8861debfc3dSmrg Examples: <code>__count __ix __s1</code> 8871debfc3dSmrg 8881debfc3dSmrg Type names and template formal-argument names: <literal>_[A-Z][^_].*</literal> 8891debfc3dSmrg 8901debfc3dSmrg Examples: <code>_Helper _CharT _N</code> 8911debfc3dSmrg 8921debfc3dSmrg Member data and function names: <literal>_M_.*</literal> 8931debfc3dSmrg 8941debfc3dSmrg Examples: <code>_M_num_elements _M_initialize ()</code> 8951debfc3dSmrg 8961debfc3dSmrg Static data members, constants, and enumerations: <literal>_S_.*</literal> 8971debfc3dSmrg 8981debfc3dSmrg Examples: <code>_S_max_elements _S_default_value</code> 8991debfc3dSmrg 9001debfc3dSmrg Don't use names in the same scope that differ only in the prefix, 9011debfc3dSmrg e.g. _S_top and _M_top. See <link linkend="coding_style.bad_identifiers">BADNAMES</link> for a list of forbidden names. 9021debfc3dSmrg (The most tempting of these seem to be and "_T" and "__sz".) 9031debfc3dSmrg 9041debfc3dSmrg Names must never have "__" internally; it would confuse name 9051debfc3dSmrg unmanglers on some targets. Also, never use "__[0-9]", same reason. 9061debfc3dSmrg 9071debfc3dSmrg -------------------------- 9081debfc3dSmrg 9091debfc3dSmrg [BY EXAMPLE] 9101debfc3dSmrg <code> 9111debfc3dSmrg 9121debfc3dSmrg #ifndef _HEADER_ 9131debfc3dSmrg #define _HEADER_ 1 9141debfc3dSmrg 9151debfc3dSmrg namespace std 9161debfc3dSmrg { 9171debfc3dSmrg class gribble 9181debfc3dSmrg { 9191debfc3dSmrg public: 9201debfc3dSmrg gribble() throw(); 9211debfc3dSmrg 9221debfc3dSmrg gribble(const gribble&); 9231debfc3dSmrg 9241debfc3dSmrg explicit 9251debfc3dSmrg gribble(int __howmany); 9261debfc3dSmrg 9271debfc3dSmrg gribble& 9281debfc3dSmrg operator=(const gribble&); 9291debfc3dSmrg 9301debfc3dSmrg virtual 9311debfc3dSmrg ~gribble() throw (); 9321debfc3dSmrg 9331debfc3dSmrg // Start with a capital letter, end with a period. 9341debfc3dSmrg inline void 9351debfc3dSmrg public_member(const char* __arg) const; 9361debfc3dSmrg 9371debfc3dSmrg // In-class function definitions should be restricted to one-liners. 9381debfc3dSmrg int 9391debfc3dSmrg one_line() { return 0 } 9401debfc3dSmrg 9411debfc3dSmrg int 9421debfc3dSmrg two_lines(const char* arg) 9431debfc3dSmrg { return strchr(arg, 'a'); } 9441debfc3dSmrg 9451debfc3dSmrg inline int 9461debfc3dSmrg three_lines(); // inline, but defined below. 9471debfc3dSmrg 9481debfc3dSmrg // Note indentation. 9491debfc3dSmrg template<typename _Formal_argument> 9501debfc3dSmrg void 9511debfc3dSmrg public_template() const throw(); 9521debfc3dSmrg 9531debfc3dSmrg template<typename _Iterator> 9541debfc3dSmrg void 9551debfc3dSmrg other_template(); 9561debfc3dSmrg 9571debfc3dSmrg private: 9581debfc3dSmrg class _Helper; 9591debfc3dSmrg 9601debfc3dSmrg int _M_private_data; 9611debfc3dSmrg int _M_more_stuff; 9621debfc3dSmrg _Helper* _M_helper; 9631debfc3dSmrg int _M_private_function(); 9641debfc3dSmrg 9651debfc3dSmrg enum _Enum 9661debfc3dSmrg { 9671debfc3dSmrg _S_one, 9681debfc3dSmrg _S_two 9691debfc3dSmrg }; 9701debfc3dSmrg 9711debfc3dSmrg static void 9721debfc3dSmrg _S_initialize_library(); 9731debfc3dSmrg }; 9741debfc3dSmrg 9751debfc3dSmrg // More-or-less-standard language features described by lack, not presence. 9761debfc3dSmrg # ifndef _G_NO_LONGLONG 9771debfc3dSmrg extern long long _G_global_with_a_good_long_name; // avoid globals! 9781debfc3dSmrg # endif 9791debfc3dSmrg 9801debfc3dSmrg // Avoid in-class inline definitions, define separately; 9811debfc3dSmrg // likewise for member class definitions: 9821debfc3dSmrg inline int 9831debfc3dSmrg gribble::public_member() const 9841debfc3dSmrg { int __local = 0; return __local; } 9851debfc3dSmrg 9861debfc3dSmrg class gribble::_Helper 9871debfc3dSmrg { 9881debfc3dSmrg int _M_stuff; 9891debfc3dSmrg 9901debfc3dSmrg friend class gribble; 9911debfc3dSmrg }; 9921debfc3dSmrg } 9931debfc3dSmrg 9941debfc3dSmrg // Names beginning with "__": only for arguments and 9951debfc3dSmrg // local variables; never use "__" in a type name, or 9961debfc3dSmrg // within any name; never use "__[0-9]". 9971debfc3dSmrg 9981debfc3dSmrg #endif /* _HEADER_ */ 9991debfc3dSmrg 10001debfc3dSmrg 10011debfc3dSmrg namespace std 10021debfc3dSmrg { 10031debfc3dSmrg template<typename T> // notice: "typename", not "class", no space 10041debfc3dSmrg long_return_value_type<with_many, args> 10051debfc3dSmrg function_name(char* pointer, // "char *pointer" is wrong. 10061debfc3dSmrg char* argument, 10071debfc3dSmrg const Reference& ref) 10081debfc3dSmrg { 10091debfc3dSmrg // int a_local; /* wrong; see below. */ 10101debfc3dSmrg if (test) 10111debfc3dSmrg { 10121debfc3dSmrg nested code 10131debfc3dSmrg } 10141debfc3dSmrg 10151debfc3dSmrg int a_local = 0; // declare variable at first use. 10161debfc3dSmrg 10171debfc3dSmrg // char a, b, *p; /* wrong */ 10181debfc3dSmrg char a = 'a'; 10191debfc3dSmrg char b = a + 1; 10201debfc3dSmrg char* c = "abc"; // each variable goes on its own line, always. 10211debfc3dSmrg 10221debfc3dSmrg // except maybe here... 10231debfc3dSmrg for (unsigned i = 0, mask = 1; mask; ++i, mask <<= 1) { 10241debfc3dSmrg // ... 10251debfc3dSmrg } 10261debfc3dSmrg } 10271debfc3dSmrg 10281debfc3dSmrg gribble::gribble() 10291debfc3dSmrg : _M_private_data(0), _M_more_stuff(0), _M_helper(0) 10301debfc3dSmrg { } 10311debfc3dSmrg 10321debfc3dSmrg int 10331debfc3dSmrg gribble::three_lines() 10341debfc3dSmrg { 10351debfc3dSmrg // doesn't fit in one line. 10361debfc3dSmrg } 10371debfc3dSmrg } // namespace std 10381debfc3dSmrg </code> 10391debfc3dSmrg </literallayout> 10401debfc3dSmrg </section> 10411debfc3dSmrg</section> 10421debfc3dSmrg 10431debfc3dSmrg<section xml:id="contrib.design_notes" xreflabel="Design Notes"><info><title>Design Notes</title></info> 10441debfc3dSmrg <?dbhtml filename="source_design_notes.html"?> 10451debfc3dSmrg 10461debfc3dSmrg <para> 10471debfc3dSmrg </para> 10481debfc3dSmrg 10491debfc3dSmrg <literallayout class="normal"> 10501debfc3dSmrg 10511debfc3dSmrg The Library 10521debfc3dSmrg ----------- 10531debfc3dSmrg 10541debfc3dSmrg This paper is covers two major areas: 10551debfc3dSmrg 10561debfc3dSmrg - Features and policies not mentioned in the standard that 10571debfc3dSmrg the quality of the library implementation depends on, including 10581debfc3dSmrg extensions and "implementation-defined" features; 10591debfc3dSmrg 10601debfc3dSmrg - Plans for required but unimplemented library features and 10611debfc3dSmrg optimizations to them. 10621debfc3dSmrg 10631debfc3dSmrg Overhead 10641debfc3dSmrg -------- 10651debfc3dSmrg 10661debfc3dSmrg The standard defines a large library, much larger than the standard 10671debfc3dSmrg C library. A naive implementation would suffer substantial overhead 10681debfc3dSmrg in compile time, executable size, and speed, rendering it unusable 10691debfc3dSmrg in many (particularly embedded) applications. The alternative demands 10701debfc3dSmrg care in construction, and some compiler support, but there is no 10711debfc3dSmrg need for library subsets. 10721debfc3dSmrg 10731debfc3dSmrg What are the sources of this overhead? There are four main causes: 10741debfc3dSmrg 10751debfc3dSmrg - The library is specified almost entirely as templates, which 10761debfc3dSmrg with current compilers must be included in-line, resulting in 10771debfc3dSmrg very slow builds as tens or hundreds of thousands of lines 10781debfc3dSmrg of function definitions are read for each user source file. 10791debfc3dSmrg Indeed, the entire SGI STL, as well as the dos Reis valarray, 10801debfc3dSmrg are provided purely as header files, largely for simplicity in 10811debfc3dSmrg porting. Iostream/locale is (or will be) as large again. 10821debfc3dSmrg 10831debfc3dSmrg - The library is very flexible, specifying a multitude of hooks 10841debfc3dSmrg where users can insert their own code in place of defaults. 10851debfc3dSmrg When these hooks are not used, any time and code expended to 10861debfc3dSmrg support that flexibility is wasted. 10871debfc3dSmrg 10881debfc3dSmrg - Templates are often described as causing to "code bloat". In 10891debfc3dSmrg practice, this refers (when it refers to anything real) to several 10901debfc3dSmrg independent processes. First, when a class template is manually 10911debfc3dSmrg instantiated in its entirely, current compilers place the definitions 10921debfc3dSmrg for all members in a single object file, so that a program linking 10931debfc3dSmrg to one member gets definitions of all. Second, template functions 10941debfc3dSmrg which do not actually depend on the template argument are, under 10951debfc3dSmrg current compilers, generated anew for each instantiation, rather 10961debfc3dSmrg than being shared with other instantiations. Third, some of the 10971debfc3dSmrg flexibility mentioned above comes from virtual functions (both in 10981debfc3dSmrg regular classes and template classes) which current linkers add 10991debfc3dSmrg to the executable file even when they manifestly cannot be called. 11001debfc3dSmrg 11011debfc3dSmrg - The library is specified to use a language feature, exceptions, 11021debfc3dSmrg which in the current gcc compiler ABI imposes a run time and 11031debfc3dSmrg code space cost to handle the possibility of exceptions even when 11041debfc3dSmrg they are not used. Under the new ABI (accessed with -fnew-abi), 11051debfc3dSmrg there is a space overhead and a small reduction in code efficiency 11061debfc3dSmrg resulting from lost optimization opportunities associated with 11071debfc3dSmrg non-local branches associated with exceptions. 11081debfc3dSmrg 11091debfc3dSmrg What can be done to eliminate this overhead? A variety of coding 11101debfc3dSmrg techniques, and compiler, linker and library improvements and 11111debfc3dSmrg extensions may be used, as covered below. Most are not difficult, 11121debfc3dSmrg and some are already implemented in varying degrees. 11131debfc3dSmrg 11141debfc3dSmrg Overhead: Compilation Time 11151debfc3dSmrg -------------------------- 11161debfc3dSmrg 11171debfc3dSmrg Providing "ready-instantiated" template code in object code archives 11181debfc3dSmrg allows us to avoid generating and optimizing template instantiations 11191debfc3dSmrg in each compilation unit which uses them. However, the number of such 11201debfc3dSmrg instantiations that are useful to provide is limited, and anyway this 11211debfc3dSmrg is not enough, by itself, to minimize compilation time. In particular, 11221debfc3dSmrg it does not reduce time spent parsing conforming headers. 11231debfc3dSmrg 11241debfc3dSmrg Quicker header parsing will depend on library extensions and compiler 11251debfc3dSmrg improvements. One approach is some variation on the techniques 11261debfc3dSmrg previously marketed as "pre-compiled headers", now standardized as 11271debfc3dSmrg support for the "export" keyword. "Exported" template definitions 11281debfc3dSmrg can be placed (once) in a "repository" -- really just a library, but 11291debfc3dSmrg of template definitions rather than object code -- to be drawn upon 11301debfc3dSmrg at link time when an instantiation is needed, rather than placed in 11311debfc3dSmrg header files to be parsed along with every compilation unit. 11321debfc3dSmrg 11331debfc3dSmrg Until "export" is implemented we can put some of the lengthy template 11341debfc3dSmrg definitions in #if guards or alternative headers so that users can skip 11351debfc3dSmrg over the full definitions when they need only the ready-instantiated 11361debfc3dSmrg specializations. 11371debfc3dSmrg 11381debfc3dSmrg To be precise, this means that certain headers which define 11391debfc3dSmrg templates which users normally use only for certain arguments 11401debfc3dSmrg can be instrumented to avoid exposing the template definitions 11411debfc3dSmrg to the compiler unless a macro is defined. For example, in 11421debfc3dSmrg <string>, we might have: 11431debfc3dSmrg 11441debfc3dSmrg template <class _CharT, ... > class basic_string { 11451debfc3dSmrg ... // member declarations 11461debfc3dSmrg }; 11471debfc3dSmrg ... // operator declarations 11481debfc3dSmrg 11491debfc3dSmrg #ifdef _STRICT_ISO_ 11501debfc3dSmrg # if _G_NO_TEMPLATE_EXPORT 11511debfc3dSmrg # include <bits/std_locale.h> // headers needed by definitions 11521debfc3dSmrg # ... 11531debfc3dSmrg # include <bits/string.tcc> // member and global template definitions. 11541debfc3dSmrg # endif 11551debfc3dSmrg #endif 11561debfc3dSmrg 11571debfc3dSmrg Users who compile without specifying a strict-ISO-conforming flag 11581debfc3dSmrg would not see many of the template definitions they now see, and rely 11591debfc3dSmrg instead on ready-instantiated specializations in the library. This 11601debfc3dSmrg technique would be useful for the following substantial components: 11611debfc3dSmrg string, locale/iostreams, valarray. It would *not* be useful or 11621debfc3dSmrg usable with the following: containers, algorithms, iterators, 11631debfc3dSmrg allocator. Since these constitute a large (though decreasing) 11641debfc3dSmrg fraction of the library, the benefit the technique offers is 11651debfc3dSmrg limited. 11661debfc3dSmrg 11671debfc3dSmrg The language specifies the semantics of the "export" keyword, but 11681debfc3dSmrg the gcc compiler does not yet support it. When it does, problems 11691debfc3dSmrg with large template inclusions can largely disappear, given some 11701debfc3dSmrg minor library reorganization, along with the need for the apparatus 11711debfc3dSmrg described above. 11721debfc3dSmrg 11731debfc3dSmrg Overhead: Flexibility Cost 11741debfc3dSmrg -------------------------- 11751debfc3dSmrg 11761debfc3dSmrg The library offers many places where users can specify operations 11771debfc3dSmrg to be performed by the library in place of defaults. Sometimes 11781debfc3dSmrg this seems to require that the library use a more-roundabout, and 11791debfc3dSmrg possibly slower, way to accomplish the default requirements than 11801debfc3dSmrg would be used otherwise. 11811debfc3dSmrg 11821debfc3dSmrg The primary protection against this overhead is thorough compiler 11831debfc3dSmrg optimization, to crush out layers of inline function interfaces. 11841debfc3dSmrg Kuck & Associates has demonstrated the practicality of this kind 11851debfc3dSmrg of optimization. 11861debfc3dSmrg 11871debfc3dSmrg The second line of defense against this overhead is explicit 11881debfc3dSmrg specialization. By defining helper function templates, and writing 11891debfc3dSmrg specialized code for the default case, overhead can be eliminated 11901debfc3dSmrg for that case without sacrificing flexibility. This takes full 11911debfc3dSmrg advantage of any ability of the optimizer to crush out degenerate 11921debfc3dSmrg code. 11931debfc3dSmrg 11941debfc3dSmrg The library specifies many virtual functions which current linkers 11951debfc3dSmrg load even when they cannot be called. Some minor improvements to the 11961debfc3dSmrg compiler and to ld would eliminate any such overhead by simply 11971debfc3dSmrg omitting virtual functions that the complete program does not call. 11981debfc3dSmrg A prototype of this work has already been done. For targets where 11991debfc3dSmrg GNU ld is not used, a "pre-linker" could do the same job. 12001debfc3dSmrg 12011debfc3dSmrg The main areas in the standard interface where user flexibility 12021debfc3dSmrg can result in overhead are: 12031debfc3dSmrg 12041debfc3dSmrg - Allocators: Containers are specified to use user-definable 12051debfc3dSmrg allocator types and objects, making tuning for the container 12061debfc3dSmrg characteristics tricky. 12071debfc3dSmrg 12081debfc3dSmrg - Locales: the standard specifies locale objects used to implement 12091debfc3dSmrg iostream operations, involving many virtual functions which use 12101debfc3dSmrg streambuf iterators. 12111debfc3dSmrg 12121debfc3dSmrg - Algorithms and containers: these may be instantiated on any type, 12131debfc3dSmrg frequently duplicating code for identical operations. 12141debfc3dSmrg 12151debfc3dSmrg - Iostreams and strings: users are permitted to use these on their 12161debfc3dSmrg own types, and specify the operations the stream must use on these 12171debfc3dSmrg types. 12181debfc3dSmrg 12191debfc3dSmrg Note that these sources of overhead are _avoidable_. The techniques 12201debfc3dSmrg to avoid them are covered below. 12211debfc3dSmrg 12221debfc3dSmrg Code Bloat 12231debfc3dSmrg ---------- 12241debfc3dSmrg 12251debfc3dSmrg In the SGI STL, and in some other headers, many of the templates 12261debfc3dSmrg are defined "inline" -- either explicitly or by their placement 12271debfc3dSmrg in class definitions -- which should not be inline. This is a 12281debfc3dSmrg source of code bloat. Matt had remarked that he was relying on 12291debfc3dSmrg the compiler to recognize what was too big to benefit from inlining, 12301debfc3dSmrg and generate it out-of-line automatically. However, this also can 12311debfc3dSmrg result in code bloat except where the linker can eliminate the extra 12321debfc3dSmrg copies. 12331debfc3dSmrg 12341debfc3dSmrg Fixing these cases will require an audit of all inline functions 12351debfc3dSmrg defined in the library to determine which merit inlining, and moving 12361debfc3dSmrg the rest out of line. This is an issue mainly in clauses 23, 25, and 12371debfc3dSmrg 27. Of course it can be done incrementally, and we should generally 12381debfc3dSmrg accept patches that move large functions out of line and into ".tcc" 12391debfc3dSmrg files, which can later be pulled into a repository. Compiler/linker 12401debfc3dSmrg improvements to recognize very large inline functions and move them 12411debfc3dSmrg out-of-line, but shared among compilation units, could make this 12421debfc3dSmrg work unnecessary. 12431debfc3dSmrg 12441debfc3dSmrg Pre-instantiating template specializations currently produces large 12451debfc3dSmrg amounts of dead code which bloats statically linked programs. The 12461debfc3dSmrg current state of the static library, libstdc++.a, is intolerable on 12471debfc3dSmrg this account, and will fuel further confused speculation about a need 12481debfc3dSmrg for a library "subset". A compiler improvement that treats each 12491debfc3dSmrg instantiated function as a separate object file, for linking purposes, 12501debfc3dSmrg would be one solution to this problem. An alternative would be to 12511debfc3dSmrg split up the manual instantiation files into dozens upon dozens of 12521debfc3dSmrg little files, each compiled separately, but an abortive attempt at 12531debfc3dSmrg this was done for <string> and, though it is far from complete, it 12541debfc3dSmrg is already a nuisance. A better interim solution (just until we have 12551debfc3dSmrg "export") is badly needed. 12561debfc3dSmrg 12571debfc3dSmrg When building a shared library, the current compiler/linker cannot 12581debfc3dSmrg automatically generate the instantiations needed. This creates a 12591debfc3dSmrg miserable situation; it means any time something is changed in the 12601debfc3dSmrg library, before a shared library can be built someone must manually 12611debfc3dSmrg copy the declarations of all templates that are needed by other parts 12621debfc3dSmrg of the library to an "instantiation" file, and add it to the build 12631debfc3dSmrg system to be compiled and linked to the library. This process is 12641debfc3dSmrg readily automated, and should be automated as soon as possible. 12651debfc3dSmrg Users building their own shared libraries experience identical 12661debfc3dSmrg frustrations. 12671debfc3dSmrg 12681debfc3dSmrg Sharing common aspects of template definitions among instantiations 12691debfc3dSmrg can radically reduce code bloat. The compiler could help a great 12701debfc3dSmrg deal here by recognizing when a function depends on nothing about 12711debfc3dSmrg a template parameter, or only on its size, and giving the resulting 12721debfc3dSmrg function a link-name "equate" that allows it to be shared with other 12731debfc3dSmrg instantiations. Implementation code could take advantage of the 12741debfc3dSmrg capability by factoring out code that does not depend on the template 12751debfc3dSmrg argument into separate functions to be merged by the compiler. 12761debfc3dSmrg 12771debfc3dSmrg Until such a compiler optimization is implemented, much can be done 12781debfc3dSmrg manually (if tediously) in this direction. One such optimization is 12791debfc3dSmrg to derive class templates from non-template classes, and move as much 12801debfc3dSmrg implementation as possible into the base class. Another is to partial- 12811debfc3dSmrg specialize certain common instantiations, such as vector<T*>, to share 12821debfc3dSmrg code for instantiations on all types T. While these techniques work, 12831debfc3dSmrg they are far from the complete solution that a compiler improvement 12841debfc3dSmrg would afford. 12851debfc3dSmrg 12861debfc3dSmrg Overhead: Expensive Language Features 12871debfc3dSmrg ------------------------------------- 12881debfc3dSmrg 12891debfc3dSmrg The main "expensive" language feature used in the standard library 12901debfc3dSmrg is exception support, which requires compiling in cleanup code with 12911debfc3dSmrg static table data to locate it, and linking in library code to use 12921debfc3dSmrg the table. For small embedded programs the amount of such library 12931debfc3dSmrg code and table data is assumed by some to be excessive. Under the 12941debfc3dSmrg "new" ABI this perception is generally exaggerated, although in some 12951debfc3dSmrg cases it may actually be excessive. 12961debfc3dSmrg 12971debfc3dSmrg To implement a library which does not use exceptions directly is 12981debfc3dSmrg not difficult given minor compiler support (to "turn off" exceptions 12991debfc3dSmrg and ignore exception constructs), and results in no great library 13001debfc3dSmrg maintenance difficulties. To be precise, given "-fno-exceptions", 13011debfc3dSmrg the compiler should treat "try" blocks as ordinary blocks, and 13021debfc3dSmrg "catch" blocks as dead code to ignore or eliminate. Compiler 13031debfc3dSmrg support is not strictly necessary, except in the case of "function 13041debfc3dSmrg try blocks"; otherwise the following macros almost suffice: 13051debfc3dSmrg 13061debfc3dSmrg #define throw(X) 13071debfc3dSmrg #define try if (true) 13081debfc3dSmrg #define catch(X) else if (false) 13091debfc3dSmrg 13101debfc3dSmrg However, there may be a need to use function try blocks in the 13111debfc3dSmrg library implementation, and use of macros in this way can make 13121debfc3dSmrg correct diagnostics impossible. Furthermore, use of this scheme 13131debfc3dSmrg would require the library to call a function to re-throw exceptions 13141debfc3dSmrg from a try block. Implementing the above semantics in the compiler 13151debfc3dSmrg is preferable. 13161debfc3dSmrg 13171debfc3dSmrg Given the support above (however implemented) it only remains to 13181debfc3dSmrg replace code that "throws" with a call to a well-documented "handler" 13191debfc3dSmrg function in a separate compilation unit which may be replaced by 13201debfc3dSmrg the user. The main source of exceptions that would be difficult 13211debfc3dSmrg for users to avoid is memory allocation failures, but users can 13221debfc3dSmrg define their own memory allocation primitives that never throw. 13231debfc3dSmrg Otherwise, the complete list of such handlers, and which library 13241debfc3dSmrg functions may call them, would be needed for users to be able to 13251debfc3dSmrg implement the necessary substitutes. (Fortunately, they have the 13261debfc3dSmrg source code.) 13271debfc3dSmrg 13281debfc3dSmrg Opportunities 13291debfc3dSmrg ------------- 13301debfc3dSmrg 13311debfc3dSmrg The template capabilities of C++ offer enormous opportunities for 13321debfc3dSmrg optimizing common library operations, well beyond what would be 13331debfc3dSmrg considered "eliminating overhead". In particular, many operations 13341debfc3dSmrg done in Glibc with macros that depend on proprietary language 13351debfc3dSmrg extensions can be implemented in pristine Standard C++. For example, 13361debfc3dSmrg the chapter 25 algorithms, and even C library functions such as strchr, 13371debfc3dSmrg can be specialized for the case of static arrays of known (small) size. 13381debfc3dSmrg 13391debfc3dSmrg Detailed optimization opportunities are identified below where 13401debfc3dSmrg the component where they would appear is discussed. Of course new 13411debfc3dSmrg opportunities will be identified during implementation. 13421debfc3dSmrg 13431debfc3dSmrg Unimplemented Required Library Features 13441debfc3dSmrg --------------------------------------- 13451debfc3dSmrg 13461debfc3dSmrg The standard specifies hundreds of components, grouped broadly by 13471debfc3dSmrg chapter. These are listed in excruciating detail in the CHECKLIST 13481debfc3dSmrg file. 13491debfc3dSmrg 13501debfc3dSmrg 17 general 13511debfc3dSmrg 18 support 13521debfc3dSmrg 19 diagnostics 13531debfc3dSmrg 20 utilities 13541debfc3dSmrg 21 string 13551debfc3dSmrg 22 locale 13561debfc3dSmrg 23 containers 13571debfc3dSmrg 24 iterators 13581debfc3dSmrg 25 algorithms 13591debfc3dSmrg 26 numerics 13601debfc3dSmrg 27 iostreams 13611debfc3dSmrg Annex D backward compatibility 13621debfc3dSmrg 13631debfc3dSmrg Anyone participating in implementation of the library should obtain 13641debfc3dSmrg a copy of the standard, ISO 14882. People in the U.S. can obtain an 13651debfc3dSmrg electronic copy for US$18 from ANSI's web site. Those from other 13661debfc3dSmrg countries should visit http://www.iso.org/ to find out the location 13671debfc3dSmrg of their country's representation in ISO, in order to know who can 13681debfc3dSmrg sell them a copy. 13691debfc3dSmrg 13701debfc3dSmrg The emphasis in the following sections is on unimplemented features 13711debfc3dSmrg and optimization opportunities. 13721debfc3dSmrg 13731debfc3dSmrg Chapter 17 General 13741debfc3dSmrg ------------------- 13751debfc3dSmrg 13761debfc3dSmrg Chapter 17 concerns overall library requirements. 13771debfc3dSmrg 13781debfc3dSmrg The standard doesn't mention threads. A multi-thread (MT) extension 13791debfc3dSmrg primarily affects operators new and delete (18), allocator (20), 13801debfc3dSmrg string (21), locale (22), and iostreams (27). The common underlying 13811debfc3dSmrg support needed for this is discussed under chapter 20. 13821debfc3dSmrg 13831debfc3dSmrg The standard requirements on names from the C headers create a 13841debfc3dSmrg lot of work, mostly done. Names in the C headers must be visible 13851debfc3dSmrg in the std:: and sometimes the global namespace; the names in the 13861debfc3dSmrg two scopes must refer to the same object. More stringent is that 13871debfc3dSmrg Koenig lookup implies that any types specified as defined in std:: 13881debfc3dSmrg really are defined in std::. Names optionally implemented as 13891debfc3dSmrg macros in C cannot be macros in C++. (An overview may be read at 13901debfc3dSmrg <http://www.cantrip.org/cheaders.html>). The scripts "inclosure" 13911debfc3dSmrg and "mkcshadow", and the directories shadow/ and cshadow/, are the 13921debfc3dSmrg beginning of an effort to conform in this area. 13931debfc3dSmrg 13941debfc3dSmrg A correct conforming definition of C header names based on underlying 13951debfc3dSmrg C library headers, and practical linking of conforming namespaced 13961debfc3dSmrg customer code with third-party C libraries depends ultimately on 13971debfc3dSmrg an ABI change, allowing namespaced C type names to be mangled into 13981debfc3dSmrg type names as if they were global, somewhat as C function names in a 13991debfc3dSmrg namespace, or C++ global variable names, are left unmangled. Perhaps 14001debfc3dSmrg another "extern" mode, such as 'extern "C-global"' would be an 14011debfc3dSmrg appropriate place for such type definitions. Such a type would 14021debfc3dSmrg affect mangling as follows: 14031debfc3dSmrg 14041debfc3dSmrg namespace A { 14051debfc3dSmrg struct X {}; 14061debfc3dSmrg extern "C-global" { // or maybe just 'extern "C"' 14071debfc3dSmrg struct Y {}; 14081debfc3dSmrg }; 14091debfc3dSmrg } 14101debfc3dSmrg void f(A::X*); // mangles to f__FPQ21A1X 14111debfc3dSmrg void f(A::Y*); // mangles to f__FP1Y 14121debfc3dSmrg 14131debfc3dSmrg (It may be that this is really the appropriate semantics for regular 14141debfc3dSmrg 'extern "C"', and 'extern "C-global"', as an extension, would not be 14151debfc3dSmrg necessary.) This would allow functions declared in non-standard C headers 14161debfc3dSmrg (and thus fixable by neither us nor users) to link properly with functions 14171debfc3dSmrg declared using C types defined in properly-namespaced headers. The 14181debfc3dSmrg problem this solves is that C headers (which C++ programmers do persist 14191debfc3dSmrg in using) frequently forward-declare C struct tags without including 14201debfc3dSmrg the header where the type is defined, as in 14211debfc3dSmrg 14221debfc3dSmrg struct tm; 14231debfc3dSmrg void munge(tm*); 14241debfc3dSmrg 14251debfc3dSmrg Without some compiler accommodation, munge cannot be called by correct 14261debfc3dSmrg C++ code using a pointer to a correctly-scoped tm* value. 14271debfc3dSmrg 14281debfc3dSmrg The current C headers use the preprocessor extension "#include_next", 14291debfc3dSmrg which the compiler complains about when run "-pedantic". 14301debfc3dSmrg (Incidentally, it appears that "-fpedantic" is currently ignored, 14311debfc3dSmrg probably a bug.) The solution in the C compiler is to use 14321debfc3dSmrg "-isystem" rather than "-I", but unfortunately in g++ this seems 14331debfc3dSmrg also to wrap the whole header in an 'extern "C"' block, so it's 14341debfc3dSmrg unusable for C++ headers. The correct solution appears to be to 14351debfc3dSmrg allow the various special include-directory options, if not given 14361debfc3dSmrg an argument, to affect subsequent include-directory options additively, 14371debfc3dSmrg so that if one said 14381debfc3dSmrg 14391debfc3dSmrg -pedantic -iprefix $(prefix) \ 14401debfc3dSmrg -idirafter -ino-pedantic -ino-extern-c -iwithprefix -I g++-v3 \ 14411debfc3dSmrg -iwithprefix -I g++-v3/ext 14421debfc3dSmrg 14431debfc3dSmrg the compiler would search $(prefix)/g++-v3 and not report 14441debfc3dSmrg pedantic warnings for files found there, but treat files in 14451debfc3dSmrg $(prefix)/g++-v3/ext pedantically. (The undocumented semantics 14461debfc3dSmrg of "-isystem" in g++ stink. Can they be rescinded? If not it 14471debfc3dSmrg must be replaced with something more rationally behaved.) 14481debfc3dSmrg 14491debfc3dSmrg All the C headers need the treatment above; in the standard these 14501debfc3dSmrg headers are mentioned in various clauses. Below, I have only 14511debfc3dSmrg mentioned those that present interesting implementation issues. 14521debfc3dSmrg 14531debfc3dSmrg The components identified as "mostly complete", below, have not been 14541debfc3dSmrg audited for conformance. In many cases where the library passes 14551debfc3dSmrg conformance tests we have non-conforming extensions that must be 14561debfc3dSmrg wrapped in #if guards for "pedantic" use, and in some cases renamed 14571debfc3dSmrg in a conforming way for continued use in the implementation regardless 14581debfc3dSmrg of conformance flags. 14591debfc3dSmrg 14601debfc3dSmrg The STL portion of the library still depends on a header 14611debfc3dSmrg stl/bits/stl_config.h full of #ifdef clauses. This apparatus 14621debfc3dSmrg should be replaced with autoconf/automake machinery. 14631debfc3dSmrg 14641debfc3dSmrg The SGI STL defines a type_traits<> template, specialized for 14651debfc3dSmrg many types in their code including the built-in numeric and 14661debfc3dSmrg pointer types and some library types, to direct optimizations of 14671debfc3dSmrg standard functions. The SGI compiler has been extended to generate 14681debfc3dSmrg specializations of this template automatically for user types, 14691debfc3dSmrg so that use of STL templates on user types can take advantage of 14701debfc3dSmrg these optimizations. Specializations for other, non-STL, types 14711debfc3dSmrg would make more optimizations possible, but extending the gcc 14721debfc3dSmrg compiler in the same way would be much better. Probably the next 14731debfc3dSmrg round of standardization will ratify this, but probably with 14741debfc3dSmrg changes, so it probably should be renamed to place it in the 14751debfc3dSmrg implementation namespace. 14761debfc3dSmrg 14771debfc3dSmrg The SGI STL also defines a large number of extensions visible in 14781debfc3dSmrg standard headers. (Other extensions that appear in separate headers 14791debfc3dSmrg have been sequestered in subdirectories ext/ and backward/.) All 14801debfc3dSmrg these extensions should be moved to other headers where possible, 14811debfc3dSmrg and in any case wrapped in a namespace (not std!), and (where kept 14821debfc3dSmrg in a standard header) girded about with macro guards. Some cannot be 14831debfc3dSmrg moved out of standard headers because they are used to implement 14841debfc3dSmrg standard features. The canonical method for accommodating these 14851debfc3dSmrg is to use a protected name, aliased in macro guards to a user-space 14861debfc3dSmrg name. Unfortunately C++ offers no satisfactory template typedef 14871debfc3dSmrg mechanism, so very ad-hoc and unsatisfactory aliasing must be used 14881debfc3dSmrg instead. 14891debfc3dSmrg 14901debfc3dSmrg Implementation of a template typedef mechanism should have the highest 14911debfc3dSmrg priority among possible extensions, on the same level as implementation 14921debfc3dSmrg of the template "export" feature. 14931debfc3dSmrg 14941debfc3dSmrg Chapter 18 Language support 14951debfc3dSmrg ---------------------------- 14961debfc3dSmrg 14971debfc3dSmrg Headers: <limits> <new> <typeinfo> <exception> 14981debfc3dSmrg C headers: <cstddef> <climits> <cfloat> <cstdarg> <csetjmp> 14991debfc3dSmrg <ctime> <csignal> <cstdlib> (also 21, 25, 26) 15001debfc3dSmrg 15011debfc3dSmrg This defines the built-in exceptions, rtti, numeric_limits<>, 15021debfc3dSmrg operator new and delete. Much of this is provided by the 15031debfc3dSmrg compiler in its static runtime library. 15041debfc3dSmrg 15051debfc3dSmrg Work to do includes defining numeric_limits<> specializations in 15061debfc3dSmrg separate files for all target architectures. Values for integer types 15071debfc3dSmrg except for bool and wchar_t are readily obtained from the C header 15081debfc3dSmrg <limits.h>, but values for the remaining numeric types (bool, wchar_t, 15091debfc3dSmrg float, double, long double) must be entered manually. This is 15101debfc3dSmrg largely dog work except for those members whose values are not 15111debfc3dSmrg easily deduced from available documentation. Also, this involves 15121debfc3dSmrg some work in target configuration to identify the correct choice of 15131debfc3dSmrg file to build against and to install. 15141debfc3dSmrg 15151debfc3dSmrg The definitions of the various operators new and delete must be 15161debfc3dSmrg made thread-safe, which depends on a portable exclusion mechanism, 15171debfc3dSmrg discussed under chapter 20. Of course there is always plenty of 15181debfc3dSmrg room for improvements to the speed of operators new and delete. 15191debfc3dSmrg 15201debfc3dSmrg <cstdarg>, in Glibc, defines some macros that gcc does not allow to 15211debfc3dSmrg be wrapped into an inline function. Probably this header will demand 15221debfc3dSmrg attention whenever a new target is chosen. The functions atexit(), 15231debfc3dSmrg exit(), and abort() in cstdlib have different semantics in C++, so 15241debfc3dSmrg must be re-implemented for C++. 15251debfc3dSmrg 15261debfc3dSmrg Chapter 19 Diagnostics 15271debfc3dSmrg ----------------------- 15281debfc3dSmrg 15291debfc3dSmrg Headers: <stdexcept> 15301debfc3dSmrg C headers: <cassert> <cerrno> 15311debfc3dSmrg 15321debfc3dSmrg This defines the standard exception objects, which are "mostly complete". 15331debfc3dSmrg Cygnus has a version, and now SGI provides a slightly different one. 15341debfc3dSmrg It makes little difference which we use. 15351debfc3dSmrg 15361debfc3dSmrg The C global name "errno", which C allows to be a variable or a macro, 15371debfc3dSmrg is required in C++ to be a macro. For MT it must typically result in 15381debfc3dSmrg a function call. 15391debfc3dSmrg 15401debfc3dSmrg Chapter 20 Utilities 15411debfc3dSmrg --------------------- 15421debfc3dSmrg Headers: <utility> <functional> <memory> 15431debfc3dSmrg C header: <ctime> (also in 18) 15441debfc3dSmrg 15451debfc3dSmrg SGI STL provides "mostly complete" versions of all the components 15461debfc3dSmrg defined in this chapter. However, the auto_ptr<> implementation 15471debfc3dSmrg is known to be wrong. Furthermore, the standard definition of it 15481debfc3dSmrg is known to be unimplementable as written. A minor change to the 15491debfc3dSmrg standard would fix it, and auto_ptr<> should be adjusted to match. 15501debfc3dSmrg 15511debfc3dSmrg Multi-threading affects the allocator implementation, and there must 15521debfc3dSmrg be configuration/installation choices for different users' MT 15531debfc3dSmrg requirements. Anyway, users will want to tune allocator options 15541debfc3dSmrg to support different target conditions, MT or no. 15551debfc3dSmrg 15561debfc3dSmrg The primitives used for MT implementation should be exposed, as an 15571debfc3dSmrg extension, for users' own work. We need cross-CPU "mutex" support, 15581debfc3dSmrg multi-processor shared-memory atomic integer operations, and single- 15591debfc3dSmrg processor uninterruptible integer operations, and all three configurable 15601debfc3dSmrg to be stubbed out for non-MT use, or to use an appropriately-loaded 15611debfc3dSmrg dynamic library for the actual runtime environment, or statically 15621debfc3dSmrg compiled in for cases where the target architecture is known. 15631debfc3dSmrg 15641debfc3dSmrg Chapter 21 String 15651debfc3dSmrg ------------------ 15661debfc3dSmrg Headers: <string> 15671debfc3dSmrg C headers: <cctype> <cwctype> <cstring> <cwchar> (also in 27) 15681debfc3dSmrg <cstdlib> (also in 18, 25, 26) 15691debfc3dSmrg 15701debfc3dSmrg We have "mostly-complete" char_traits<> implementations. Many of the 15711debfc3dSmrg char_traits<char> operations might be optimized further using existing 15721debfc3dSmrg proprietary language extensions. 15731debfc3dSmrg 15741debfc3dSmrg We have a "mostly-complete" basic_string<> implementation. The work 15751debfc3dSmrg to manually instantiate char and wchar_t specializations in object 15761debfc3dSmrg files to improve link-time behavior is extremely unsatisfactory, 15771debfc3dSmrg literally tripling library-build time with no commensurate improvement 15781debfc3dSmrg in static program link sizes. It must be redone. (Similar work is 15791debfc3dSmrg needed for some components in clauses 22 and 27.) 15801debfc3dSmrg 15811debfc3dSmrg Other work needed for strings is MT-safety, as discussed under the 15821debfc3dSmrg chapter 20 heading. 15831debfc3dSmrg 15841debfc3dSmrg The standard C type mbstate_t from <cwchar> and used in char_traits<> 15851debfc3dSmrg must be different in C++ than in C, because in C++ the default constructor 15861debfc3dSmrg value mbstate_t() must be the "base" or "ground" sequence state. 15871debfc3dSmrg (According to the likely resolution of a recently raised Core issue, 15881debfc3dSmrg this may become unnecessary. However, there are other reasons to 15891debfc3dSmrg use a state type not as limited as whatever the C library provides.) 15901debfc3dSmrg If we might want to provide conversions from (e.g.) internally- 15911debfc3dSmrg represented EUC-wide to externally-represented Unicode, or vice- 15921debfc3dSmrg versa, the mbstate_t we choose will need to be more accommodating 15931debfc3dSmrg than what might be provided by an underlying C library. 15941debfc3dSmrg 15951debfc3dSmrg There remain some basic_string template-member functions which do 15961debfc3dSmrg not overload properly with their non-template brethren. The infamous 15971debfc3dSmrg hack akin to what was done in vector<> is needed, to conform to 15981debfc3dSmrg 23.1.1 para 10. The CHECKLIST items for basic_string marked 'X', 15991debfc3dSmrg or incomplete, are so marked for this reason. 16001debfc3dSmrg 16011debfc3dSmrg Replacing the string iterators, which currently are simple character 16021debfc3dSmrg pointers, with class objects would greatly increase the safety of the 16031debfc3dSmrg client interface, and also permit a "debug" mode in which range, 16041debfc3dSmrg ownership, and validity are rigorously checked. The current use of 16051debfc3dSmrg raw pointers as string iterators is evil. vector<> iterators need the 16061debfc3dSmrg same treatment. Note that the current implementation freely mixes 16071debfc3dSmrg pointers and iterators, and that must be fixed before safer iterators 16081debfc3dSmrg can be introduced. 16091debfc3dSmrg 16101debfc3dSmrg Some of the functions in <cstring> are different from the C version. 16111debfc3dSmrg generally overloaded on const and non-const argument pointers. For 16121debfc3dSmrg example, in <cstring> strchr is overloaded. The functions isupper 16131debfc3dSmrg etc. in <cctype> typically implemented as macros in C are functions 16141debfc3dSmrg in C++, because they are overloaded with others of the same name 16151debfc3dSmrg defined in <locale>. 16161debfc3dSmrg 16171debfc3dSmrg Many of the functions required in <cwctype> and <cwchar> cannot be 16181debfc3dSmrg implemented using underlying C facilities on intended targets because 16191debfc3dSmrg such facilities only partly exist. 16201debfc3dSmrg 16211debfc3dSmrg Chapter 22 Locale 16221debfc3dSmrg ------------------ 16231debfc3dSmrg Headers: <locale> 16241debfc3dSmrg C headers: <clocale> 16251debfc3dSmrg 16261debfc3dSmrg We have a "mostly complete" class locale, with the exception of 16271debfc3dSmrg code for constructing, and handling the names of, named locales. 16281debfc3dSmrg The ways that locales are named (particularly when categories 16291debfc3dSmrg (e.g. LC_TIME, LC_COLLATE) are different) varies among all target 16301debfc3dSmrg environments. This code must be written in various versions and 16311debfc3dSmrg chosen by configuration parameters. 16321debfc3dSmrg 16331debfc3dSmrg Members of many of the facets defined in <locale> are stubs. Generally, 16341debfc3dSmrg there are two sets of facets: the base class facets (which are supposed 16351debfc3dSmrg to implement the "C" locale) and the "byname" facets, which are supposed 16361debfc3dSmrg to read files to determine their behavior. The base ctype<>, collate<>, 16371debfc3dSmrg and numpunct<> facets are "mostly complete", except that the table of 16381debfc3dSmrg bitmask values used for "is" operations, and corresponding mask values, 16391debfc3dSmrg are still defined in libio and just included/linked. (We will need to 16401debfc3dSmrg implement these tables independently, soon, but should take advantage 16411debfc3dSmrg of libio where possible.) The num_put<>::put members for integer types 16421debfc3dSmrg are "mostly complete". 16431debfc3dSmrg 16441debfc3dSmrg A complete list of what has and has not been implemented may be 16451debfc3dSmrg found in CHECKLIST. However, note that the current definition of 16461debfc3dSmrg codecvt<wchar_t,char,mbstate_t> is wrong. It should simply write 16471debfc3dSmrg out the raw bytes representing the wide characters, rather than 16481debfc3dSmrg trying to convert each to a corresponding single "char" value. 16491debfc3dSmrg 16501debfc3dSmrg Some of the facets are more important than others. Specifically, 16511debfc3dSmrg the members of ctype<>, numpunct<>, num_put<>, and num_get<> facets 16521debfc3dSmrg are used by other library facilities defined in <string>, <istream>, 16531debfc3dSmrg and <ostream>, and the codecvt<> facet is used by basic_filebuf<> 16541debfc3dSmrg in <fstream>, so a conforming iostream implementation depends on 16551debfc3dSmrg these. 16561debfc3dSmrg 16571debfc3dSmrg The "long long" type eventually must be supported, but code mentioning 16581debfc3dSmrg it should be wrapped in #if guards to allow pedantic-mode compiling. 16591debfc3dSmrg 16601debfc3dSmrg Performance of num_put<> and num_get<> depend critically on 16611debfc3dSmrg caching computed values in ios_base objects, and on extensions 16621debfc3dSmrg to the interface with streambufs. 16631debfc3dSmrg 16641debfc3dSmrg Specifically: retrieving a copy of the locale object, extracting 16651debfc3dSmrg the needed facets, and gathering data from them, for each call to 16661debfc3dSmrg (e.g.) operator<< would be prohibitively slow. To cache format 16671debfc3dSmrg data for use by num_put<> and num_get<> we have a _Format_cache<> 16681debfc3dSmrg object stored in the ios_base::pword() array. This is constructed 16691debfc3dSmrg and initialized lazily, and is organized purely for utility. It 16701debfc3dSmrg is discarded when a new locale with different facets is imbued. 16711debfc3dSmrg 16721debfc3dSmrg Using only the public interfaces of the iterator arguments to the 16731debfc3dSmrg facet functions would limit performance by forbidding "vector-style" 16741debfc3dSmrg character operations. The streambuf iterator optimizations are 16751debfc3dSmrg described under chapter 24, but facets can also bypass the streambuf 16761debfc3dSmrg iterators via explicit specializations and operate directly on the 16771debfc3dSmrg streambufs, and use extended interfaces to get direct access to the 16781debfc3dSmrg streambuf internal buffer arrays. These extensions are mentioned 16791debfc3dSmrg under chapter 27. These optimizations are particularly important 16801debfc3dSmrg for input parsing. 16811debfc3dSmrg 16821debfc3dSmrg Unused virtual members of locale facets can be omitted, as mentioned 16831debfc3dSmrg above, by a smart linker. 16841debfc3dSmrg 16851debfc3dSmrg Chapter 23 Containers 16861debfc3dSmrg ---------------------- 16871debfc3dSmrg Headers: <deque> <list> <queue> <stack> <vector> <map> <set> <bitset> 16881debfc3dSmrg 16891debfc3dSmrg All the components in chapter 23 are implemented in the SGI STL. 16901debfc3dSmrg They are "mostly complete"; they include a large number of 16911debfc3dSmrg nonconforming extensions which must be wrapped. Some of these 16921debfc3dSmrg are used internally and must be renamed or duplicated. 16931debfc3dSmrg 16941debfc3dSmrg The SGI components are optimized for large-memory environments. For 16951debfc3dSmrg embedded targets, different criteria might be more appropriate. Users 16961debfc3dSmrg will want to be able to tune this behavior. We should provide 16971debfc3dSmrg ways for users to compile the library with different memory usage 16981debfc3dSmrg characteristics. 16991debfc3dSmrg 17001debfc3dSmrg A lot more work is needed on factoring out common code from different 17011debfc3dSmrg specializations to reduce code size here and in chapter 25. The 17021debfc3dSmrg easiest fix for this would be a compiler/ABI improvement that allows 17031debfc3dSmrg the compiler to recognize when a specialization depends only on the 17041debfc3dSmrg size (or other gross quality) of a template argument, and allow the 17051debfc3dSmrg linker to share the code with similar specializations. In its 17061debfc3dSmrg absence, many of the algorithms and containers can be partial- 17071debfc3dSmrg specialized, at least for the case of pointers, but this only solves 17081debfc3dSmrg a small part of the problem. Use of a type_traits-style template 17091debfc3dSmrg allows a few more optimization opportunities, more if the compiler 17101debfc3dSmrg can generate the specializations automatically. 17111debfc3dSmrg 17121debfc3dSmrg As an optimization, containers can specialize on the default allocator 17131debfc3dSmrg and bypass it, or take advantage of details of its implementation 17141debfc3dSmrg after it has been improved upon. 17151debfc3dSmrg 17161debfc3dSmrg Replacing the vector iterators, which currently are simple element 17171debfc3dSmrg pointers, with class objects would greatly increase the safety of the 17181debfc3dSmrg client interface, and also permit a "debug" mode in which range, 17191debfc3dSmrg ownership, and validity are rigorously checked. The current use of 17201debfc3dSmrg pointers for iterators is evil. 17211debfc3dSmrg 17221debfc3dSmrg As mentioned for chapter 24, the deque iterator is a good example of 17231debfc3dSmrg an opportunity to implement a "staged" iterator that would benefit 17241debfc3dSmrg from specializations of some algorithms. 17251debfc3dSmrg 17261debfc3dSmrg Chapter 24 Iterators 17271debfc3dSmrg --------------------- 17281debfc3dSmrg Headers: <iterator> 17291debfc3dSmrg 17301debfc3dSmrg Standard iterators are "mostly complete", with the exception of 17311debfc3dSmrg the stream iterators, which are not yet templatized on the 17321debfc3dSmrg stream type. Also, the base class template iterator<> appears 17331debfc3dSmrg to be wrong, so everything derived from it must also be wrong, 17341debfc3dSmrg currently. 17351debfc3dSmrg 17361debfc3dSmrg The streambuf iterators (currently located in stl/bits/std_iterator.h, 17371debfc3dSmrg but should be under bits/) can be rewritten to take advantage of 17381debfc3dSmrg friendship with the streambuf implementation. 17391debfc3dSmrg 17401debfc3dSmrg Matt Austern has identified opportunities where certain iterator 17411debfc3dSmrg types, particularly including streambuf iterators and deque 17421debfc3dSmrg iterators, have a "two-stage" quality, such that an intermediate 17431debfc3dSmrg limit can be checked much more quickly than the true limit on 17441debfc3dSmrg range operations. If identified with a member of iterator_traits, 17451debfc3dSmrg algorithms may be specialized for this case. Of course the 17461debfc3dSmrg iterators that have this quality can be identified by specializing 17471debfc3dSmrg a traits class. 17481debfc3dSmrg 17491debfc3dSmrg Many of the algorithms must be specialized for the streambuf 17501debfc3dSmrg iterators, to take advantage of block-mode operations, in order 17511debfc3dSmrg to allow iostream/locale operations' performance not to suffer. 17521debfc3dSmrg It may be that they could be treated as staged iterators and 17531debfc3dSmrg take advantage of those optimizations. 17541debfc3dSmrg 17551debfc3dSmrg Chapter 25 Algorithms 17561debfc3dSmrg ---------------------- 17571debfc3dSmrg Headers: <algorithm> 17581debfc3dSmrg C headers: <cstdlib> (also in 18, 21, 26)) 17591debfc3dSmrg 17601debfc3dSmrg The algorithms are "mostly complete". As mentioned above, they 17611debfc3dSmrg are optimized for speed at the expense of code and data size. 17621debfc3dSmrg 17631debfc3dSmrg Specializations of many of the algorithms for non-STL types would 17641debfc3dSmrg give performance improvements, but we must use great care not to 17651debfc3dSmrg interfere with fragile template overloading semantics for the 17661debfc3dSmrg standard interfaces. Conventionally the standard function template 17671debfc3dSmrg interface is an inline which delegates to a non-standard function 17681debfc3dSmrg which is then overloaded (this is already done in many places in 17691debfc3dSmrg the library). Particularly appealing opportunities for the sake of 17701debfc3dSmrg iostream performance are for copy and find applied to streambuf 17711debfc3dSmrg iterators or (as noted elsewhere) for staged iterators, of which 17721debfc3dSmrg the streambuf iterators are a good example. 17731debfc3dSmrg 17741debfc3dSmrg The bsearch and qsort functions cannot be overloaded properly as 17751debfc3dSmrg required by the standard because gcc does not yet allow overloading 17761debfc3dSmrg on the extern-"C"-ness of a function pointer. 17771debfc3dSmrg 17781debfc3dSmrg Chapter 26 Numerics 17791debfc3dSmrg -------------------- 17801debfc3dSmrg Headers: <complex> <valarray> <numeric> 17811debfc3dSmrg C headers: <cmath>, <cstdlib> (also 18, 21, 25) 17821debfc3dSmrg 17831debfc3dSmrg Numeric components: Gabriel dos Reis's valarray, Drepper's complex, 17841debfc3dSmrg and the few algorithms from the STL are "mostly done". Of course 17851debfc3dSmrg optimization opportunities abound for the numerically literate. It 17861debfc3dSmrg is not clear whether the valarray implementation really conforms 17871debfc3dSmrg fully, in the assumptions it makes about aliasing (and lack thereof) 17881debfc3dSmrg in its arguments. 17891debfc3dSmrg 17901debfc3dSmrg The C div() and ldiv() functions are interesting, because they are the 17911debfc3dSmrg only case where a C library function returns a class object by value. 17921debfc3dSmrg Since the C++ type div_t must be different from the underlying C type 17931debfc3dSmrg (which is in the wrong namespace) the underlying functions div() and 17941debfc3dSmrg ldiv() cannot be re-used efficiently. Fortunately they are trivial to 17951debfc3dSmrg re-implement. 17961debfc3dSmrg 17971debfc3dSmrg Chapter 27 Iostreams 17981debfc3dSmrg --------------------- 17991debfc3dSmrg Headers: <iosfwd> <streambuf> <ios> <ostream> <istream> <iostream> 18001debfc3dSmrg <iomanip> <sstream> <fstream> 18011debfc3dSmrg C headers: <cstdio> <cwchar> (also in 21) 18021debfc3dSmrg 18031debfc3dSmrg Iostream is currently in a very incomplete state. <iosfwd>, <iomanip>, 18041debfc3dSmrg ios_base, and basic_ios<> are "mostly complete". basic_streambuf<> and 18051debfc3dSmrg basic_ostream<> are well along, but basic_istream<> has had little work 18061debfc3dSmrg done. The standard stream objects, <sstream> and <fstream> have been 18071debfc3dSmrg started; basic_filebuf<> "write" functions have been implemented just 18081debfc3dSmrg enough to do "hello, world". 18091debfc3dSmrg 18101debfc3dSmrg Most of the istream and ostream operators << and >> (with the exception 18111debfc3dSmrg of the op<<(integer) ones) have not been changed to use locale primitives, 18121debfc3dSmrg sentry objects, or char_traits members. 18131debfc3dSmrg 18141debfc3dSmrg All these templates should be manually instantiated for char and 18151debfc3dSmrg wchar_t in a way that links only used members into user programs. 18161debfc3dSmrg 18171debfc3dSmrg Streambuf is fertile ground for optimization extensions. An extended 18181debfc3dSmrg interface giving iterator access to its internal buffer would be very 18191debfc3dSmrg useful for other library components. 18201debfc3dSmrg 18211debfc3dSmrg Iostream operations (primarily operators << and >>) can take advantage 18221debfc3dSmrg of the case where user code has not specified a locale, and bypass locale 18231debfc3dSmrg operations entirely. The current implementation of op<</num_put<>::put, 18241debfc3dSmrg for the integer types, demonstrates how they can cache encoding details 18251debfc3dSmrg from the locale on each operation. There is lots more room for 18261debfc3dSmrg optimization in this area. 18271debfc3dSmrg 18281debfc3dSmrg The definition of the relationship between the standard streams 18291debfc3dSmrg cout et al. and stdout et al. requires something like a "stdiobuf". 18301debfc3dSmrg The SGI solution of using double-indirection to actually use a 18311debfc3dSmrg stdio FILE object for buffering is unsatisfactory, because it 18321debfc3dSmrg interferes with peephole loop optimizations. 18331debfc3dSmrg 18341debfc3dSmrg The <sstream> header work has begun. stringbuf can benefit from 18351debfc3dSmrg friendship with basic_string<> and basic_string<>::_Rep to use 18361debfc3dSmrg those objects directly as buffers, and avoid allocating and making 18371debfc3dSmrg copies. 18381debfc3dSmrg 18391debfc3dSmrg The basic_filebuf<> template is a complex beast. It is specified to 18401debfc3dSmrg use the locale facet codecvt<> to translate characters between native 18411debfc3dSmrg files and the locale character encoding. In general this involves 18421debfc3dSmrg two buffers, one of "char" representing the file and another of 18431debfc3dSmrg "char_type", for the stream, with codecvt<> translating. The process 18441debfc3dSmrg is complicated by the variable-length nature of the translation, and 18451debfc3dSmrg the need to seek to corresponding places in the two representations. 18461debfc3dSmrg For the case of basic_filebuf<char>, when no translation is needed, 18471debfc3dSmrg a single buffer suffices. A specialized filebuf can be used to reduce 18481debfc3dSmrg code space overhead when no locale has been imbued. Matt Austern's 18491debfc3dSmrg work at SGI will be useful, perhaps directly as a source of code, or 18501debfc3dSmrg at least as an example to draw on. 18511debfc3dSmrg 18521debfc3dSmrg Filebuf, almost uniquely (cf. operator new), depends heavily on 18531debfc3dSmrg underlying environmental facilities. In current releases iostream 18541debfc3dSmrg depends fairly heavily on libio constant definitions, but it should 18551debfc3dSmrg be made independent. It also depends on operating system primitives 18561debfc3dSmrg for file operations. There is immense room for optimizations using 18571debfc3dSmrg (e.g.) mmap for reading. The shadow/ directory wraps, besides the 18581debfc3dSmrg standard C headers, the libio.h and unistd.h headers, for use mainly 18591debfc3dSmrg by filebuf. These wrappings have not been completed, though there 18601debfc3dSmrg is scaffolding in place. 18611debfc3dSmrg 18621debfc3dSmrg The encapsulation of certain C header <cstdio> names presents an 18631debfc3dSmrg interesting problem. It is possible to define an inline std::fprintf() 18641debfc3dSmrg implemented in terms of the 'extern "C"' vfprintf(), but there is no 18651debfc3dSmrg standard vfscanf() to use to implement std::fscanf(). It appears that 18661debfc3dSmrg vfscanf but be re-implemented in C++ for targets where no vfscanf 18671debfc3dSmrg extension has been defined. This is interesting in that it seems 18681debfc3dSmrg to be the only significant case in the C library where this kind of 18691debfc3dSmrg rewriting is necessary. (Of course Glibc provides the vfscanf() 18701debfc3dSmrg extension.) (The functions related to exit() must be rewritten 18711debfc3dSmrg for other reasons.) 18721debfc3dSmrg 18731debfc3dSmrg 18741debfc3dSmrg Annex D 18751debfc3dSmrg ------- 18761debfc3dSmrg Headers: <strstream> 18771debfc3dSmrg 18781debfc3dSmrg Annex D defines many non-library features, and many minor 18791debfc3dSmrg modifications to various headers, and a complete header. 18801debfc3dSmrg It is "mostly done", except that the libstdc++-2 <strstream> 18811debfc3dSmrg header has not been adopted into the library, or checked to 18821debfc3dSmrg verify that it matches the draft in those details that were 18831debfc3dSmrg clarified by the committee. Certainly it must at least be 18841debfc3dSmrg moved into the std namespace. 18851debfc3dSmrg 18861debfc3dSmrg We still need to wrap all the deprecated features in #if guards 18871debfc3dSmrg so that pedantic compile modes can detect their use. 18881debfc3dSmrg 18891debfc3dSmrg Nonstandard Extensions 18901debfc3dSmrg ---------------------- 18911debfc3dSmrg Headers: <iostream.h> <strstream.h> <hash> <rbtree> 18921debfc3dSmrg <pthread_alloc> <stdiobuf> (etc.) 18931debfc3dSmrg 18941debfc3dSmrg User code has come to depend on a variety of nonstandard components 18951debfc3dSmrg that we must not omit. Much of this code can be adopted from 18961debfc3dSmrg libstdc++-v2 or from the SGI STL. This particularly includes 18971debfc3dSmrg <iostream.h>, <strstream.h>, and various SGI extensions such 18981debfc3dSmrg as <hash_map.h>. Many of these are already placed in the 18991debfc3dSmrg subdirectories ext/ and backward/. (Note that it is better to 19001debfc3dSmrg include them via "<backward/hash_map.h>" or "<ext/hash_map>" than 19011debfc3dSmrg to search the subdirectory itself via a "-I" directive. 19021debfc3dSmrg </literallayout> 19031debfc3dSmrg</section> 19041debfc3dSmrg 19051debfc3dSmrg</appendix> 1906