Commit a5356269 by Felix Natter Committed by Phil Edwards

porting-howto.xml: check in v0.9.4

2001-11-05  Felix Natter  <fnatter@gmx.net>

	* docs/html/17_intro/porting-howto.xml:  check in v0.9.4
	* docs/html/17_intro/porting-howto.html:  regenerate

From-SVN: r46793
parent ac4f7ad9
2001-11-05 Felix Natter <fnatter@gmx.net>
* docs/html/17_intro/porting-howto.xml: check in v0.9.4
* docs/html/17_intro/porting-howto.html: regenerate
2001-11-02 Loren J. Rittle <ljrittle@acm.org> 2001-11-02 Loren J. Rittle <ljrittle@acm.org>
* include/bits/stl_threads.h (_Atomic_swap): Only enable path * include/bits/stl_threads.h (_Atomic_swap): Only enable path
......
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
<div><div class="legalnotice"> <div><div class="legalnotice">
<p class="legalnotice-title"><b>Legal Notice</b></p> <p class="legalnotice-title"><b>Legal Notice</b></p>
<p> <p>
This document can be distributed under the FDL This document can be distributed under the FDL
(<a href="http://www.gnu.org" target="_top">www.gnu.org</a>) (<a href="http://www.gnu.org" target="_top">www.gnu.org</a>)
</p> </p>
</div></div> </div></div>
<div><p class="pubdate">Tue Jun 5 20:07:49 2001</p></div> <div><p class="pubdate">Tue Jun 5 20:07:49 2001</p></div>
...@@ -32,8 +32,8 @@ ...@@ -32,8 +32,8 @@
<td align="left">fnatter</td> <td align="left">fnatter</td>
</tr> </tr>
<tr><td align="left" colspan="3">First released version using docbook-xml <tr><td align="left" colspan="3">First released version using docbook-xml
+ second upload to libstdc++-page. + second upload to libstdc++-page.
</td></tr> </td></tr>
<tr> <tr>
<td align="left">Revision 0.9</td> <td align="left">Revision 0.9</td>
<td align="left">Wed Sep 6 02:59:32 2000</td> <td align="left">Wed Sep 6 02:59:32 2000</td>
...@@ -46,37 +46,46 @@ ...@@ -46,37 +46,46 @@
<td align="left">fnatter</td> <td align="left">fnatter</td>
</tr> </tr>
<tr><td align="left" colspan="3">added information about why file-descriptors are not in the <tr><td align="left" colspan="3">added information about why file-descriptors are not in the
standard</td></tr> standard</td></tr>
<tr> <tr>
<td align="left">Revision 0.9.2</td> <td align="left">Revision 0.9.2</td>
<td align="left">Tue Jun 5 20:07:49 2001</td> <td align="left">Tue Jun 5 20:07:49 2001</td>
<td align="left">fnatter</td> <td align="left">fnatter</td>
</tr> </tr>
<tr><td align="left" colspan="3"> <tr><td align="left" colspan="3">
a fix, added hint on increased portability of C-shadow-headers, a fix, added hint on increased portability of C-shadow-headers,
added autoconf-test HAVE_CONTAINER_AT added autoconf-test HAVE_CONTAINER_AT
</td></tr> </td></tr>
<tr> <tr>
<td align="left">Revision 0.9.3</td> <td align="left">Revision 0.9.3</td>
<td align="left">Fri Jun 29 16:15:56 2001</td> <td align="left">Fri Jun 29 16:15:56 2001</td>
<td align="left">fnatter</td> <td align="left">fnatter</td>
</tr> </tr>
<tr><td align="left" colspan="3"> <tr><td align="left" colspan="3">
changed signature of nonstandard filebuf-constructor and changed signature of nonstandard filebuf-constructor and
update the section on filebuf::attach to point to ../ext/howto.html, update the section on filebuf::attach to point to ../ext/howto.html,
added link to ../21/strings/howto.html added link to ../21/strings/howto.html
in sec-stringstream, changed &lt;link&gt;-tags to have content in sec-stringstream, changed &lt;link&gt;-tags to have content
(so that these links work), (so that these links work),
replace &quot;user-space&quot; by &quot;global namespace&quot; replace &quot;user-space&quot; by &quot;global namespace&quot;
add note about gcc 3.0 and shadow-headers add note about gcc 3.0 and shadow-headers
add section about ostream::form and istream::scan add section about ostream::form and istream::scan
sec-vector-at: remove hint to modify headers sec-vector-at: remove hint to modify headers
fix spelling error in sec-stringstream fix spelling error in sec-stringstream
</td></tr> </td></tr>
<tr>
<td align="left">Revision 0.9.4</td>
<td align="left">Mon Nov 5 17:01:04 2001</td>
<td align="left">fnatter</td>
</tr>
<tr><td align="left" colspan="3">
rewrite section 1.1.3 because of gnu.gcc.help-post by
Juergen Heinzl
</td></tr>
</table></div></div> </table></div></div>
<div><div class="abstract"> <div><div class="abstract">
<p> <p>
<a name="id2695641"></a><b>Abstract</b> <a name="id2697062"></a><b>Abstract</b>
</p> </p>
<p> <p>
Some notes on porting applications from libstdc++-2.90 (or earlier Some notes on porting applications from libstdc++-2.90 (or earlier
...@@ -162,19 +171,19 @@ ...@@ -162,19 +171,19 @@
things: things:
<div class="itemizedlist"><ul> <div class="itemizedlist"><ul>
<li><p> <li><p>
<a name="id2695691"></a>wrap your code in <b>namespace std { <a name="id2697113"></a>wrap your code in <b>namespace std {
... }</b> =&gt; This is not an option because only symbols ... }</b> =&gt; This is not an option because only symbols
from the standard c++-library are defined in namespace std::. from the standard c++-library are defined in namespace std::.
</p></li> </p></li>
<li><p> <li><p>
<a name="id2695698"></a>put a kind of <a name="id2697126"></a>put a kind of
<i>using-declaration</i> in your source (either <i>using-declaration</i> in your source (either
<b>using namespace std;</b> or i.e. <b>using <b>using namespace std;</b> or i.e. <b>using
std::string;</b>) =&gt; works well for source-files, but std::string;</b>) =&gt; works well for source-files, but
cannot be used in header-files. cannot be used in header-files.
</p></li> </p></li>
<li><p> <li><p>
<a name="id2695717"></a>use a <i>fully qualified name</i> for <a name="id2697047"></a>use a <i>fully qualified name</i> for
each libstdc++-symbol (i.e. <b>std::string</b>, each libstdc++-symbol (i.e. <b>std::string</b>,
<b>std::cout</b>) =&gt; can always be used <b>std::cout</b>) =&gt; can always be used
</p></li> </p></li>
...@@ -257,12 +266,32 @@ ...@@ -257,12 +266,32 @@
<p> <p>
If some compilers complain about <b>using If some compilers complain about <b>using
std::string;</b>, and if the &quot;hack&quot; for gtk-- mentioned above std::string;</b>, and if the &quot;hack&quot; for gtk-- mentioned above
does not work, then it might be a good idea to define a macro does not work, then I see two solutions:
NS_STD, which is defined to either &quot;&quot; or &quot;std&quot;
based on an autoconf-test. Then you should be able to use <div class="itemizedlist"><ul>
<b>NS_STD::string</b>, which will evaluate to <li><p>
<b>::string</b> (&quot;string in the global namespace&quot;) on <a name="id2698648"></a>
systems that do not put string in std::. (This is untested) Define <b>std::</b> as a macro if the compiler
doesn't know about <b>std::</b>.
<pre class="programlisting">
#ifdef OLD_COMPILER
#define std
#endif
</pre>
(thanks to Juergen Heinzl who posted this solution on
gnu.gcc.help)
</p></li>
<li><p>
<a name="id2698680"></a>
Define a macro NS_STD, which is defined to
either &quot;&quot; or &quot;std&quot;
based on an autoconf-test. Then you should be able to use
<b>NS_STD::string</b>, which will evaluate to
<b>::string</b> (&quot;string in the global namespace&quot;) on
systems that do not put string in std::. (This is untested)
</p></li>
</ul></div>
</p> </p>
</div> </div>
<div class="section"> <div class="section">
...@@ -276,7 +305,7 @@ ...@@ -276,7 +305,7 @@
</p> </p>
<div class="table"> <div class="table">
<p> <p>
<a name="id2696268"></a><b>Table 1. Namespace std:: in Open-Source programs</b> <a name="id2698746"></a><b>Table 1. Namespace std:: in Open-Source programs</b>
</p> </p>
<table summary="Namespace std:: in Open-Source programs" border="1"> <table summary="Namespace std:: in Open-Source programs" border="1">
<colgroup> <colgroup>
...@@ -310,7 +339,7 @@ ...@@ -310,7 +339,7 @@
</div> </div>
<div class="table"> <div class="table">
<p> <p>
<a name="id2696334"></a><b>Table 2. Notations for categories</b> <a name="id2698876"></a><b>Table 2. Notations for categories</b>
</p> </p>
<table summary="Notations for categories" border="1"> <table summary="Notations for categories" border="1">
<colgroup> <colgroup>
...@@ -377,21 +406,21 @@ ...@@ -377,21 +406,21 @@
</p> </p>
<p> <p>
When using libstdc++-v3, you can use When using libstdc++-v3, you can use
<div class="funcsynopsis" id="id2696909"> <div class="funcsynopsis" id="id2692860">
<p> <p>
<a name="id2696909"></a><pre class="funcsynopsisinfo"> <a name="id2692860"></a><pre class="funcsynopsisinfo">
#include &lt;fstream&gt; #include &lt;fstream&gt;
</pre> </pre>
<p><code><code class="funcdef"> <p><code><code class="funcdef">
<b class="fsfunc">basic_filebuf&lt;...&gt;::basic_filebuf&lt;...&gt; <b class="fsfunc">basic_filebuf&lt;...&gt;::basic_filebuf&lt;...&gt;
</b> </b>
</code>(<var class="pdparam">file</var>, <var class="pdparam">mode</var>, <var class="pdparam">size</var>);<br>__c_file_type* <var class="pdparam">file</var>;<br>ios_base::open_mode <var class="pdparam">mode</var>;<br>int <var class="pdparam">size</var>;</code></p> </code>(<var class="pdparam">file</var>, <var class="pdparam">mode</var>, <var class="pdparam">size</var>);<br>__c_file_type* <var class="pdparam">file</var>;<br>ios_base::open_mode <var class="pdparam">mode</var>;<br>int <var class="pdparam">size</var>;</code></p>
<p> <p>
</div> </div>
but the the signature of this constructor has changed often, and but the the signature of this constructor has changed often, and
it might change again. For the current state of this, check it might change again. For the current state of this, check
<a href="../ext/howto.html" target="_top">the howto for extensions</a>. <a href="../ext/howto.html" target="_top">the howto for extensions</a>.
</p> </p>
<p> <p>
For a portable solution (among systems which use For a portable solution (among systems which use
filedescriptors), you need to implement a subclass of filedescriptors), you need to implement a subclass of
...@@ -410,8 +439,8 @@ ...@@ -410,8 +439,8 @@
source-code</a>. source-code</a>.
</p> </p>
<p> <p>
The old C++-headers (iostream.h etc.) are available, but gcc generates The old C++-headers (iostream.h etc.) are available, but gcc generates
a warning that you are using deprecated headers. a warning that you are using deprecated headers.
</p> </p>
<div class="section"> <div class="section">
<a name="sec-cheaders"></a><div class="titlepage"><div><h3 class="title"> <a name="sec-cheaders"></a><div class="titlepage"><div><h3 class="title">
...@@ -441,7 +470,7 @@ ...@@ -441,7 +470,7 @@
For more information on this, and for information on how the For more information on this, and for information on how the
GNU C++ implementation might reuse (&quot;shadow&quot;) the C GNU C++ implementation might reuse (&quot;shadow&quot;) the C
library-functions, have a look at <a href="http://www.cantrip.org/cheaders.html" target="_top"> library-functions, have a look at <a href="http://www.cantrip.org/cheaders.html" target="_top">
www.cantrip.org</a>. www.cantrip.org</a>.
</p> </p>
</div> </div>
<div class="section"> <div class="section">
...@@ -455,8 +484,8 @@ ...@@ -455,8 +484,8 @@
In earlier versions of the standard, In earlier versions of the standard,
<tt>&lt;fstream.h&gt;</tt>, <tt>&lt;fstream.h&gt;</tt>,
<tt>&lt;ostream.h&gt;</tt> <tt>&lt;ostream.h&gt;</tt>
and <tt>&lt;istream.h&gt;</tt> and <tt>&lt;istream.h&gt;</tt>
used to define used to define
<b>cout</b>, <b>cin</b> and so on. Because <b>cout</b>, <b>cin</b> and so on. Because
of the templatized iostreams in libstdc++-v3, you need to include of the templatized iostreams in libstdc++-v3, you need to include
<tt>&lt;iostream&gt;</tt> <tt>&lt;iostream&gt;</tt>
...@@ -473,18 +502,18 @@ ...@@ -473,18 +502,18 @@
fixes for existing uses of iterators. fixes for existing uses of iterators.
<div class="itemizedlist"><ul> <div class="itemizedlist"><ul>
<li><p> <li><p>
<a name="id2692127"></a>you cannot do <a name="id2693156"></a>you cannot do
<b>ostream::operator&lt;&lt;(iterator)</b> to <b>ostream::operator&lt;&lt;(iterator)</b> to
print the address of the iterator =&gt; use print the address of the iterator =&gt; use
<b>operator&lt;&lt; &amp;*iterator</b> instead ? <b>operator&lt;&lt; &amp;*iterator</b> instead ?
</p></li> </p></li>
<li><p> <li><p>
<a name="id2697070"></a>you cannot clear an iterator's reference <a name="id2693255"></a>you cannot clear an iterator's reference
(<b>iterator = 0</b>) =&gt; use (<b>iterator = 0</b>) =&gt; use
<b>iterator = iterator_type();</b> ? <b>iterator = iterator_type();</b> ?
</p></li> </p></li>
<li><p> <li><p>
<a name="id2697221"></a><b>if (iterator)</b> won't work any <a name="id2693277"></a><b>if (iterator)</b> won't work any
more =&gt; use <b>if (iterator != iterator_type())</b> more =&gt; use <b>if (iterator != iterator_type())</b>
?</p></li> ?</p></li>
</ul></div> </ul></div>
...@@ -501,7 +530,7 @@ ...@@ -501,7 +530,7 @@
<tt>&lt;ctype.h&gt;</tt> <tt>&lt;ctype.h&gt;</tt>
-functionality as macros (isspace, isalpha etc.). Libstdc++-v3 -functionality as macros (isspace, isalpha etc.). Libstdc++-v3
&quot;shadows&quot; these macros as described in the <a href="#sec-cheaders">section about &quot;shadows&quot; these macros as described in the <a href="#sec-cheaders">section about
c-headers</a>. c-headers</a>.
</p> </p>
<p> <p>
Older implementations of libstdc++ (g++-2 for egcs 1.x and g++-3 Older implementations of libstdc++ (g++-2 for egcs 1.x and g++-3
...@@ -552,8 +581,8 @@ ...@@ -552,8 +581,8 @@
--enable-cshadow-headers is currently broken. As a result, shadow --enable-cshadow-headers is currently broken. As a result, shadow
headers are not being searched.... headers are not being searched....
' '
This is now outdated, but gcc 3.0 still does not have fully This is now outdated, but gcc 3.0 still does not have fully
compliant &quot;shadow headers&quot;. compliant &quot;shadow headers&quot;.
</p> </p>
</div> </div>
<div class="section"> <div class="section">
...@@ -646,10 +675,10 @@ ...@@ -646,10 +675,10 @@
<a name="sec-scan-form"></a><span class="label">11.</span> <span class="title">GNU Extensions ostream::form and istream::scan</span> <a name="sec-scan-form"></a><span class="label">11.</span> <span class="title">GNU Extensions ostream::form and istream::scan</span>
</h2></div></div> </h2></div></div>
<p> <p>
These are not supported any more - use These are not supported any more - use
<a href="#sec-stringstream"> <a href="#sec-stringstream">
stringstreams</a> instead. stringstreams</a> instead.
</p> </p>
</div> </div>
<div class="section"> <div class="section">
<a name="sec-stringstream"></a><div class="titlepage"><div><h2 class="title" style="clear: all"> <a name="sec-stringstream"></a><div class="titlepage"><div><h2 class="title" style="clear: all">
...@@ -669,20 +698,20 @@ ...@@ -669,20 +698,20 @@
</pre> </pre>
<div class="itemizedlist"><ul> <div class="itemizedlist"><ul>
<li><p> <li><p>
<a name="id2692504"></a> <b>strstream</b> is considered to be <a name="id2693683"></a> <b>strstream</b> is considered to be
deprecated deprecated
</p></li> </p></li>
<li><p> <li><p>
<a name="id2692452"></a> <b>strstream</b> is limited to <a name="id2693629"></a> <b>strstream</b> is limited to
<b>char</b> <b>char</b>
</p></li> </p></li>
<li><p> <li><p>
<a name="id2692539"></a> with <b>ostringstream</b> you don't <a name="id2693718"></a> with <b>ostringstream</b> you don't
have to take care of terminating the string or freeing its have to take care of terminating the string or freeing its
memory memory
</p></li> </p></li>
<li><p> <li><p>
<a name="id2692552"></a> <b>istringstream</b> can be re-filled <a name="id2693735"></a> <b>istringstream</b> can be re-filled
(clear(); str(input);) (clear(); str(input);)
</p></li> </p></li>
</ul></div> </ul></div>
...@@ -739,18 +768,18 @@ ...@@ -739,18 +768,18 @@
void fromString(const string&amp; input, X&amp; any) void fromString(const string&amp; input, X&amp; any)
{ {
#ifdef HAVE_SSTREAM #ifdef HAVE_SSTREAM
std::istringstream iss(input); std::istringstream iss(input);
#else #else
std::istrstream iss(input.c_str()); std::istrstream iss(input.c_str());
#endif #endif
X temp; X temp;
iss &gt;&gt; temp; iss &gt;&gt; temp;
if (iss.fail()) if (iss.fail())
throw runtime_error(..) throw runtime_error(..)
any = temp; any = temp;
} }
</pre> </pre>
Another example of using stringstreams is in <a href="../21_strings/howto.html" target="_top">this howto</a>. Another example of using stringstreams is in <a href="../21_strings/howto.html" target="_top">this howto</a>.
</p> </p>
<p> <p>
I have read the Josuttis book on Standard C++, so some information I have read the Josuttis book on Standard C++, so some information
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
<!-- TODO: <!-- TODO:
o remove //@label: use automatic numbering o remove //@label: use automatic numbering
o make this work: <link linkend="sec-gtkmm-hack" endterm="sec-gtkmm-hack.title"/>. o make this work: <link linkend="sec-gtkmm-hack" endterm="sec-gtkmm-hack.title"/>.
o clean up the section-numbering
--> -->
<article class = "whitepaper" id = "libstdc++-porting-howto" lang = "en"> <article class = "whitepaper" id = "libstdc++-porting-howto" lang = "en">
...@@ -36,63 +37,72 @@ o make this work: <link linkend="sec-gtkmm-hack" endterm="sec-gtkmm-hack.title"/ ...@@ -36,63 +37,72 @@ o make this work: <link linkend="sec-gtkmm-hack" endterm="sec-gtkmm-hack.title"/
</address> </address>
<revhistory> <revhistory>
<revision> <revision>
<revnumber>0.5</revnumber> <revnumber>0.5</revnumber>
<date>Thu Jun 1 13:06:50 2000</date> <date>Thu Jun 1 13:06:50 2000</date>
<authorinitials>fnatter</authorinitials> <authorinitials>fnatter</authorinitials>
<revremark>First docbook-version.</revremark> <revremark>First docbook-version.</revremark>
</revision> </revision>
<revision> <revision>
<revnumber>0.8</revnumber> <revnumber>0.8</revnumber>
<date>Sun Jul 30 20:28:40 2000</date> <date>Sun Jul 30 20:28:40 2000</date>
<authorinitials>fnatter</authorinitials> <authorinitials>fnatter</authorinitials>
<revremark>First released version using docbook-xml <revremark>First released version using docbook-xml
+ second upload to libstdc++-page. + second upload to libstdc++-page.
</revremark> </revremark>
</revision> </revision>
<revision> <revision>
<revnumber>0.9</revnumber> <revnumber>0.9</revnumber>
<date>Wed Sep 6 02:59:32 2000</date> <date>Wed Sep 6 02:59:32 2000</date>
<authorinitials>fnatter</authorinitials> <authorinitials>fnatter</authorinitials>
<revremark>5 new sections.</revremark> <revremark>5 new sections.</revremark>
</revision> </revision>
<revision> <revision>
<revnumber>0.9.1</revnumber> <revnumber>0.9.1</revnumber>
<date>Sat Sep 23 14:20:15 2000</date> <date>Sat Sep 23 14:20:15 2000</date>
<authorinitials>fnatter</authorinitials> <authorinitials>fnatter</authorinitials>
<revremark>added information about why file-descriptors are not in the <revremark>added information about why file-descriptors are not in the
standard</revremark> standard</revremark>
</revision> </revision>
<revision> <revision>
<revnumber>0.9.2</revnumber> <revnumber>0.9.2</revnumber>
<date>Tue Jun 5 20:07:49 2001</date> <date>Tue Jun 5 20:07:49 2001</date>
<authorinitials>fnatter</authorinitials> <authorinitials>fnatter</authorinitials>
<revremark> <revremark>
a fix, added hint on increased portability of C-shadow-headers, a fix, added hint on increased portability of C-shadow-headers,
added autoconf-test HAVE_CONTAINER_AT added autoconf-test HAVE_CONTAINER_AT
</revremark> </revremark>
</revision> </revision>
<revision> <revision>
<revnumber>0.9.3</revnumber> <revnumber>0.9.3</revnumber>
<date>Fri Jun 29 16:15:56 2001</date> <date>Fri Jun 29 16:15:56 2001</date>
<authorinitials>fnatter</authorinitials> <authorinitials>fnatter</authorinitials>
<revremark> <revremark>
changed signature of nonstandard filebuf-constructor and changed signature of nonstandard filebuf-constructor and
update the section on filebuf::attach to point to ../ext/howto.html, update the section on filebuf::attach to point to ../ext/howto.html,
added link to ../21/strings/howto.html added link to ../21/strings/howto.html
in sec-stringstream, changed &lt;link&gt;-tags to have content in sec-stringstream, changed &lt;link&gt;-tags to have content
(so that these links work), (so that these links work),
replace "user-space" by "global namespace" replace "user-space" by "global namespace"
add note about gcc 3.0 and shadow-headers add note about gcc 3.0 and shadow-headers
add section about ostream::form and istream::scan add section about ostream::form and istream::scan
sec-vector-at: remove hint to modify headers sec-vector-at: remove hint to modify headers
fix spelling error in sec-stringstream fix spelling error in sec-stringstream
</revremark> </revremark>
</revision>
<revision>
<revnumber>0.9.4</revnumber>
<date>Mon Nov 5 17:01:04 2001</date>
<authorinitials>fnatter</authorinitials>
<revremark>
rewrite section 1.1.3 because of gnu.gcc.help-post by
Juergen Heinzl
</revremark>
</revision> </revision>
</revhistory> </revhistory>
<legalnotice><title>Legal Notice</title> <legalnotice><title>Legal Notice</title>
<para> <para>
This document can be distributed under the FDL This document can be distributed under the FDL
(<ulink url = "http://www.gnu.org">www.gnu.org</ulink>) (<ulink url = "http://www.gnu.org">www.gnu.org</ulink>)
</para> </para>
</legalnotice> </legalnotice>
...@@ -216,12 +226,31 @@ o make this work: <link linkend="sec-gtkmm-hack" endterm="sec-gtkmm-hack.title"/ ...@@ -216,12 +226,31 @@ o make this work: <link linkend="sec-gtkmm-hack" endterm="sec-gtkmm-hack.title"/
<para> <para>
If some compilers complain about <command>using If some compilers complain about <command>using
std::string;</command>, and if the "hack" for gtk-- mentioned above std::string;</command>, and if the "hack" for gtk-- mentioned above
does not work, then it might be a good idea to define a macro does not work, then I see two solutions:
<symbol>NS_STD</symbol>, which is defined to either "" or "std"
based on an autoconf-test. Then you should be able to use <itemizedlist>
<command>NS_STD::string</command>, which will evaluate to <listitem><para>
<command>::string</command> ("string in the global namespace") on Define <command>std::</command> as a macro if the compiler
systems that do not put string in std::. (This is untested) doesn't know about <command>std::</command>.
<programlisting>
#ifdef OLD_COMPILER
#define std
#endif
</programlisting>
(thanks to Juergen Heinzl who posted this solution on
gnu.gcc.help)
</para></listitem>
<listitem><para>
Define a macro <symbol>NS_STD</symbol>, which is defined to
either "" or "std"
based on an autoconf-test. Then you should be able to use
<command>NS_STD::string</command>, which will evaluate to
<command>::string</command> ("string in the global namespace") on
systems that do not put string in std::. (This is untested)
</para></listitem>
</itemizedlist>
</para> </para>
</section> </section>
...@@ -288,7 +317,7 @@ o make this work: <link linkend="sec-gtkmm-hack" endterm="sec-gtkmm-hack.title"/ ...@@ -288,7 +317,7 @@ o make this work: <link linkend="sec-gtkmm-hack" endterm="sec-gtkmm-hack.title"/
As you can see, this currently lacks an example of a project As you can see, this currently lacks an example of a project
which uses libstdc++-symbols in headers in a back-portable way which uses libstdc++-symbols in headers in a back-portable way
(except for Gtk--: see the <link linkend="sec-gtkmm-hack" (except for Gtk--: see the <link linkend="sec-gtkmm-hack"
endterm="sec-gtkmm-hack.title">section on the gtkmm-hack</link>). endterm="sec-gtkmm-hack.title">section on the gtkmm-hack</link>).
</para> </para>
</section> </section>
</section> <!-- end of namespace-section --> </section> <!-- end of namespace-section -->
...@@ -330,19 +359,19 @@ o make this work: <link linkend="sec-gtkmm-hack" endterm="sec-gtkmm-hack.title"/ ...@@ -330,19 +359,19 @@ o make this work: <link linkend="sec-gtkmm-hack" endterm="sec-gtkmm-hack.title"/
</funcsynopsisinfo> </funcsynopsisinfo>
<funcprototype> <funcprototype>
<funcdef> <funcdef>
<function>basic_filebuf&lt;...&gt;::basic_filebuf&lt;...&gt; <function>basic_filebuf&lt;...&gt;::basic_filebuf&lt;...&gt;
</function> </function>
</funcdef> </funcdef>
<paramdef>__c_file_type* <parameter>file</parameter></paramdef> <paramdef>__c_file_type* <parameter>file</parameter></paramdef>
<paramdef>ios_base::open_mode <parameter>mode</parameter></paramdef> <paramdef>ios_base::open_mode <parameter>mode</parameter></paramdef>
<paramdef>int <parameter>size</parameter></paramdef> <paramdef>int <parameter>size</parameter></paramdef>
</funcprototype> </funcprototype>
</funcsynopsis> </funcsynopsis>
but the the signature of this constructor has changed often, and but the the signature of this constructor has changed often, and
it might change again. For the current state of this, check it might change again. For the current state of this, check
<ulink url="../ext/howto.html">the howto for extensions</ulink>. <ulink url="../ext/howto.html">the howto for extensions</ulink>.
</para> </para>
<para> <para>
For a portable solution (among systems which use For a portable solution (among systems which use
filedescriptors), you need to implement a subclass of filedescriptors), you need to implement a subclass of
<command>std::streambuf</command> (or <command>std::streambuf</command> (or
...@@ -359,8 +388,8 @@ o make this work: <link linkend="sec-gtkmm-hack" endterm="sec-gtkmm-hack.title"/ ...@@ -359,8 +388,8 @@ o make this work: <link linkend="sec-gtkmm-hack" endterm="sec-gtkmm-hack.title"/
source-code</ulink>. source-code</ulink>.
</para> </para>
<para> <para>
The old C++-headers (iostream.h etc.) are available, but gcc generates The old C++-headers (iostream.h etc.) are available, but gcc generates
a warning that you are using deprecated headers. a warning that you are using deprecated headers.
</para> </para>
<section id = "sec-cheaders" label = "4.1"> <section id = "sec-cheaders" label = "4.1">
...@@ -372,13 +401,13 @@ o make this work: <link linkend="sec-gtkmm-hack" endterm="sec-gtkmm-hack.title"/ ...@@ -372,13 +401,13 @@ o make this work: <link linkend="sec-gtkmm-hack" endterm="sec-gtkmm-hack.title"/
omitting the extension (.h). For example, instead of using omitting the extension (.h). For example, instead of using
<filename class="headerfile">&lt;math.h&gt;</filename>, you <filename class="headerfile">&lt;math.h&gt;</filename>, you
should use <filename class = should use <filename class =
"headerfile">&lt;cmath&gt;</filename>. In some cases this has "headerfile">&lt;cmath&gt;</filename>. In some cases this has
the advantage that the C++-header is more standardized than the advantage that the C++-header is more standardized than
the C-header (i.e. <filename the C-header (i.e. <filename
class="headerfile">&lt;ctime&gt;</filename> (almost) class="headerfile">&lt;ctime&gt;</filename> (almost)
corresponds to either <filename class = corresponds to either <filename class =
"headerfile">&lt;time.h&gt;</filename> or <filename class = "headerfile">&lt;time.h&gt;</filename> or <filename class =
"headerfile">&lt;sys/time.h&gt;</filename>). "headerfile">&lt;sys/time.h&gt;</filename>).
The standard specifies that if you include the C-style header The standard specifies that if you include the C-style header
(<filename class = "headerfile">&lt;math.h&gt;</filename> in (<filename class = "headerfile">&lt;math.h&gt;</filename> in
...@@ -386,7 +415,7 @@ o make this work: <link linkend="sec-gtkmm-hack" endterm="sec-gtkmm-hack.title"/ ...@@ -386,7 +415,7 @@ o make this work: <link linkend="sec-gtkmm-hack" endterm="sec-gtkmm-hack.title"/
namespace and in namespace <command>std::</command> (but namespace and in namespace <command>std::</command> (but
libstdc++ does not yet have fully compliant headers) On the libstdc++ does not yet have fully compliant headers) On the
other hand, if you include only the new header (i.e. <filename other hand, if you include only the new header (i.e. <filename
class = "headerfile">&lt;cmath&gt;</filename>), the symbols class = "headerfile">&lt;cmath&gt;</filename>), the symbols
will only be defined in namespace <command>std::</command> will only be defined in namespace <command>std::</command>
(and macros will be converted to inline-functions). (and macros will be converted to inline-functions).
</para> </para>
...@@ -394,8 +423,8 @@ o make this work: <link linkend="sec-gtkmm-hack" endterm="sec-gtkmm-hack.title"/ ...@@ -394,8 +423,8 @@ o make this work: <link linkend="sec-gtkmm-hack" endterm="sec-gtkmm-hack.title"/
For more information on this, and for information on how the For more information on this, and for information on how the
GNU C++ implementation might reuse ("shadow") the C GNU C++ implementation might reuse ("shadow") the C
library-functions, have a look at <ulink library-functions, have a look at <ulink
url="http://www.cantrip.org/cheaders.html"> url="http://www.cantrip.org/cheaders.html">
www.cantrip.org</ulink>. www.cantrip.org</ulink>.
</para> </para>
</section> </section>
...@@ -408,8 +437,8 @@ o make this work: <link linkend="sec-gtkmm-hack" endterm="sec-gtkmm-hack.title"/ ...@@ -408,8 +437,8 @@ o make this work: <link linkend="sec-gtkmm-hack" endterm="sec-gtkmm-hack.title"/
In earlier versions of the standard, In earlier versions of the standard,
<filename class="headerfile">&lt;fstream.h&gt;</filename>, <filename class="headerfile">&lt;fstream.h&gt;</filename>,
<filename class="headerfile">&lt;ostream.h&gt;</filename> <filename class="headerfile">&lt;ostream.h&gt;</filename>
and <filename class="headerfile">&lt;istream.h&gt;</filename> and <filename class="headerfile">&lt;istream.h&gt;</filename>
used to define used to define
<command>cout</command>, <command>cin</command> and so on. Because <command>cout</command>, <command>cin</command> and so on. Because
of the templatized iostreams in libstdc++-v3, you need to include of the templatized iostreams in libstdc++-v3, you need to include
<filename class = "headerfile">&lt;iostream&gt;</filename> <filename class = "headerfile">&lt;iostream&gt;</filename>
...@@ -452,8 +481,8 @@ o make this work: <link linkend="sec-gtkmm-hack" endterm="sec-gtkmm-hack.title"/ ...@@ -452,8 +481,8 @@ o make this work: <link linkend="sec-gtkmm-hack" endterm="sec-gtkmm-hack.title"/
<filename class="headerfile">&lt;ctype.h&gt;</filename> <filename class="headerfile">&lt;ctype.h&gt;</filename>
-functionality as macros (isspace, isalpha etc.). Libstdc++-v3 -functionality as macros (isspace, isalpha etc.). Libstdc++-v3
"shadows" these macros as described in the <link "shadows" these macros as described in the <link
linkend="sec-cheaders" endterm="sec-cheaders.title">section about linkend="sec-cheaders" endterm="sec-cheaders.title">section about
c-headers</link>. c-headers</link>.
</para> </para>
<para> <para>
Older implementations of libstdc++ (g++-2 for egcs 1.x and g++-3 Older implementations of libstdc++ (g++-2 for egcs 1.x and g++-3
...@@ -478,7 +507,7 @@ o make this work: <link linkend="sec-gtkmm-hack" endterm="sec-gtkmm-hack.title"/ ...@@ -478,7 +507,7 @@ o make this work: <link linkend="sec-gtkmm-hack" endterm="sec-gtkmm-hack.title"/
Another solution which would fix g++ is to tell the user to modify a Another solution which would fix g++ is to tell the user to modify a
header-file so that g++-2 (egcs 1.x) and g++-3 (gcc 2.95.x) define a header-file so that g++-2 (egcs 1.x) and g++-3 (gcc 2.95.x) define a
macro which tells <filename macro which tells <filename
class="headerfile">&lt;ctype.h&gt;</filename> to define functions class="headerfile">&lt;ctype.h&gt;</filename> to define functions
instead of macros: instead of macros:
<programlisting> <programlisting>
// This keeps isalnum, et al from being propagated as macros. // This keeps isalnum, et al from being propagated as macros.
...@@ -492,7 +521,7 @@ o make this work: <link linkend="sec-gtkmm-hack" endterm="sec-gtkmm-hack.title"/ ...@@ -492,7 +521,7 @@ o make this work: <link linkend="sec-gtkmm-hack" endterm="sec-gtkmm-hack.title"/
<para> <para>
Another problem arises if you put a <command>using namespace Another problem arises if you put a <command>using namespace
std;</command> declaration at the top, and include <filename class std;</command> declaration at the top, and include <filename class
= "headerfile">&lt;ctype.h&gt;</filename>. This will result in = "headerfile">&lt;ctype.h&gt;</filename>. This will result in
ambiguities between the definitions in the global namespace ambiguities between the definitions in the global namespace
(<filename class = "headerfile">&lt;ctype.h&gt;</filename>) and the (<filename class = "headerfile">&lt;ctype.h&gt;</filename>) and the
definitions in namespace <command>std::</command> definitions in namespace <command>std::</command>
...@@ -506,8 +535,8 @@ o make this work: <link linkend="sec-gtkmm-hack" endterm="sec-gtkmm-hack.title"/ ...@@ -506,8 +535,8 @@ o make this work: <link linkend="sec-gtkmm-hack" endterm="sec-gtkmm-hack.title"/
--enable-cshadow-headers is currently broken. As a result, shadow --enable-cshadow-headers is currently broken. As a result, shadow
headers are not being searched.... headers are not being searched....
</quote> </quote>
This is now outdated, but gcc 3.0 still does not have fully This is now outdated, but gcc 3.0 still does not have fully
compliant "shadow headers". compliant "shadow headers".
</para> </para>
</section> </section>
...@@ -593,12 +622,12 @@ o make this work: <link linkend="sec-gtkmm-hack" endterm="sec-gtkmm-hack.title"/ ...@@ -593,12 +622,12 @@ o make this work: <link linkend="sec-gtkmm-hack" endterm="sec-gtkmm-hack.title"/
</section> </section>
<section id="sec-scan-form" label="11"> <section id="sec-scan-form" label="11">
<title>GNU Extensions ostream::form and istream::scan</title> <title>GNU Extensions ostream::form and istream::scan</title>
<para> <para>
These are not supported any more - use These are not supported any more - use
<link linkend="sec-stringstream" endterm="sec-stringstream.title"> <link linkend="sec-stringstream" endterm="sec-stringstream.title">
stringstreams</link> instead. stringstreams</link> instead.
</para> </para>
</section> </section>
<section id="sec-stringstream" label="12"> <section id="sec-stringstream" label="12">
...@@ -606,10 +635,10 @@ o make this work: <link linkend="sec-gtkmm-hack" endterm="sec-gtkmm-hack.title"/ ...@@ -606,10 +635,10 @@ o make this work: <link linkend="sec-gtkmm-hack" endterm="sec-gtkmm-hack.title"/
<para> <para>
Libstdc++-v3 provides the new Libstdc++-v3 provides the new
<command>i/ostringstream</command>-classes, (<filename <command>i/ostringstream</command>-classes, (<filename
class="headerfile">&lt;sstream&gt;</filename>), but for compatibility class="headerfile">&lt;sstream&gt;</filename>), but for compatibility
with older implementations you still have to use with older implementations you still have to use
<command>i/ostrstream</command> (<filename <command>i/ostrstream</command> (<filename
class="headerfile">&lt;strstream&gt;</filename>): class="headerfile">&lt;strstream&gt;</filename>):
<programlisting> <programlisting>
#ifdef HAVE_SSTREAM #ifdef HAVE_SSTREAM
#include &lt;sstream&gt; #include &lt;sstream&gt;
...@@ -689,19 +718,19 @@ o make this work: <link linkend="sec-gtkmm-hack" endterm="sec-gtkmm-hack.title"/ ...@@ -689,19 +718,19 @@ o make this work: <link linkend="sec-gtkmm-hack" endterm="sec-gtkmm-hack.title"/
void fromString(const string&amp; input, X&amp; any) void fromString(const string&amp; input, X&amp; any)
{ {
#ifdef HAVE_SSTREAM #ifdef HAVE_SSTREAM
std::istringstream iss(input); std::istringstream iss(input);
#else #else
std::istrstream iss(input.c_str()); std::istrstream iss(input.c_str());
#endif #endif
X temp; X temp;
iss >> temp; iss >> temp;
if (iss.fail()) if (iss.fail())
throw runtime_error(..) throw runtime_error(..)
any = temp; any = temp;
} }
</programlisting> </programlisting>
Another example of using stringstreams is in <ulink Another example of using stringstreams is in <ulink
url="../21_strings/howto.html">this howto</ulink>. url="../21_strings/howto.html">this howto</ulink>.
</para> </para>
<para> <para>
I have read the Josuttis book on Standard C++, so some information I have read the Josuttis book on Standard C++, so some information
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment