2 |
7u83 |
1 |
<!-- Crown Copyright (c) 1998 -->
|
|
|
2 |
<HTML>
|
|
|
3 |
<HEAD>
|
|
|
4 |
<TITLE>
|
|
|
5 |
C++ Producer Guide: Standard library
|
|
|
6 |
</TITLE>
|
|
|
7 |
</HEAD>
|
|
|
8 |
<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000FF" VLINK="#400080" ALINK="#FF0000">
|
|
|
9 |
|
|
|
10 |
<H1>C++ Producer Guide</H1>
|
|
|
11 |
<H3>March 1998</H3>
|
|
|
12 |
<A HREF="style.html"><IMG SRC="../images/next.gif" ALT="next section"></A>
|
|
|
13 |
<A HREF="lib.html"><IMG SRC="../images/prev.gif" ALT="previous section"></A>
|
|
|
14 |
<A HREF="index.html"><IMG SRC="../images/top.gif" ALT="current document"></A>
|
|
|
15 |
<A HREF="../index.html"><IMG SRC="../images/home.gif" ALT="TenDRA home page">
|
|
|
16 |
</A>
|
|
|
17 |
<IMG SRC="../images/no_index.gif" ALT="document index"><P>
|
|
|
18 |
<HR>
|
|
|
19 |
|
|
|
20 |
<DL>
|
|
|
21 |
<DT><A HREF="#porting"><B>2.7.1</B> - Common porting problems</A><DD>
|
|
|
22 |
<DT><A HREF="#libio"><B>2.7.2</B> - Porting <CODE>libio</CODE></A><DD>
|
|
|
23 |
</DL>
|
|
|
24 |
<HR>
|
|
|
25 |
|
|
|
26 |
<H2>2.7. Standard library</H2>
|
|
|
27 |
<P>
|
|
|
28 |
At present the default implementation contains only a very small fraction
|
|
|
29 |
of the ISO C++ library, namely those headers -
|
|
|
30 |
<CODE><exception></CODE>, <CODE><new></CODE> and
|
|
|
31 |
<CODE><typeinfo></CODE> - which are an integral part of the
|
|
|
32 |
language specification. These headers are also those which require
|
|
|
33 |
the most cooperation between the producer and the library implementation,
|
|
|
34 |
as described in the <A HREF="lib.html">previous section</A>.
|
|
|
35 |
</P>
|
|
|
36 |
<P>
|
|
|
37 |
It is suggested that if further library components are required then
|
|
|
38 |
they be acquired from third parties. It should be noted however that
|
|
|
39 |
such libraries may require <A HREF="#porting">some effort</A> to be
|
|
|
40 |
ported to an ISO compliant compiler; for example, some information
|
|
|
41 |
on porting the <CODE>libio</CODE> component of <CODE>libg++</CODE>,
|
|
|
42 |
which contains some very compiler-dependent code, are
|
|
|
43 |
<A HREF="#libio">given below</A>. Libraries compiled with other C++
|
|
|
44 |
compilers may not link correctly with modules compiled using <CODE>tcc</CODE>.
|
|
|
45 |
</P>
|
|
|
46 |
|
|
|
47 |
<HR>
|
|
|
48 |
<H3><A NAME="porting">2.7.1. Common porting problems</A></H3>
|
|
|
49 |
<P>
|
|
|
50 |
Experience in porting pre-ISO C++ programs has shown that the following
|
|
|
51 |
new ISO C++ features tend to cause the most problems:
|
|
|
52 |
<OL>
|
|
|
53 |
<LI><A HREF="pragma.html#implicit">Implicit <CODE>int</CODE></A> has
|
|
|
54 |
been banned.
|
|
|
55 |
<LI><A HREF="pragma.html#string">String literals are now <CODE>const</CODE>
|
|
|
56 |
</A>, although in simple assignments the <CODE>const</CODE> is
|
|
|
57 |
implicitly removed.
|
|
|
58 |
<LI>The scope of a <A HREF="pragma.html#for">variable declared in
|
|
|
59 |
a for-init-statement</A> is the <CODE>for</CODE> statement itself.
|
|
|
60 |
<LI><A HREF="lib.html#mangle">Variables have linkage</A> and so should
|
|
|
61 |
be declared <CODE>extern "C"</CODE> if appropriate.
|
|
|
62 |
<LI>The standard C library is now declared in the <CODE>std</CODE>
|
|
|
63 |
namespace.
|
|
|
64 |
<LI>The <A HREF="pragma.html#template">template compilation model</A>
|
|
|
65 |
has been clarified. The notation for explicit instantiation and
|
|
|
66 |
specialisation has changed.
|
|
|
67 |
<LI>Templates are analysed at their point of definition as well as
|
|
|
68 |
their point of instantiation.
|
|
|
69 |
<LI><A HREF="pragma.html#keyword">New keywords</A> have been introduced.
|
|
|
70 |
</OL>
|
|
|
71 |
Note that many of these features have controlling <CODE>#pragma</CODE>
|
|
|
72 |
directives, so that it is possible to switch to using the pre-ISO
|
|
|
73 |
features.
|
|
|
74 |
</P>
|
|
|
75 |
|
|
|
76 |
<HR>
|
|
|
77 |
<H3><A NAME="libio">2.7.2. Porting <CODE>libio</CODE></A></H3>
|
|
|
78 |
<P>
|
|
|
79 |
Perhaps the library component which is most likely to be required
|
|
|
80 |
is
|
|
|
81 |
<CODE><iostream></CODE>. A readily available freeware implementation
|
|
|
82 |
of a pre-ISO (i.e. non-template) <CODE><iostream></CODE>
|
|
|
83 |
package is given by the <CODE>libio</CODE> component of <CODE>libg++</CODE>.
|
|
|
84 |
This section describes some of the problems encountered in porting
|
|
|
85 |
this package (version 2.7.1).
|
|
|
86 |
</P>
|
|
|
87 |
<P>
|
|
|
88 |
The <A HREF="man.html"><CODE>tcc</CODE> compiler flags</A> used in
|
|
|
89 |
porting <CODE>libio</CODE> were:
|
|
|
90 |
<PRE>
|
|
|
91 |
tcc -Yposix -Yc++ -sC:cc
|
|
|
92 |
</PRE>
|
|
|
93 |
indicating that the POSIX API is to be used and that the <CODE>.cc</CODE>
|
|
|
94 |
suffix is used to identify C++ source files.
|
|
|
95 |
</P>
|
|
|
96 |
<P>
|
|
|
97 |
In <CODE>iostream.h</CODE>, <CODE>cin</CODE>, <CODE>cout</CODE>,
|
|
|
98 |
<CODE>cerr</CODE> and <CODE>clog</CODE> should be declared with C
|
|
|
99 |
linkage, otherwise the C++ producer includes the type in the
|
|
|
100 |
<A HREF="lib.html#mangle">mangled name</A> and the fake
|
|
|
101 |
<CODE>iostream</CODE> hacks in <CODE>stdstream.cc</CODE> don't work.
|
|
|
102 |
The definition of <CODE>EOF</CODE> in this header can cause problems
|
|
|
103 |
if both <CODE>iostream.h</CODE> and <CODE>stdio.h</CODE> are included.
|
|
|
104 |
In this case <CODE>stdio.h</CODE> should be included first.
|
|
|
105 |
</P>
|
|
|
106 |
<P>
|
|
|
107 |
In <CODE>stdstream.cc</CODE>, the <A HREF="lib.html#derive">correct
|
|
|
108 |
definitions</A> for the fake <CODE>iostream</CODE> structures are
|
|
|
109 |
as follows:
|
|
|
110 |
<PRE>
|
|
|
111 |
struct _fake_istream::myfields {
|
|
|
112 |
_ios_fields *vb ; // pointer to virtual base class ios
|
|
|
113 |
_IO_ssize_t _gcount ; // istream fields
|
|
|
114 |
void *vptr ; // pointer to virtual function table
|
|
|
115 |
} ;
|
|
|
116 |
|
|
|
117 |
struct _fake_ostream::myfields {
|
|
|
118 |
_ios_fields *vb ; // pointer to virtual base class ios
|
|
|
119 |
void *vptr ; // pointer to virtual function table
|
|
|
120 |
} ;
|
|
|
121 |
</PRE>
|
|
|
122 |
The fake definition macros are then defined as follows:
|
|
|
123 |
<PRE>
|
|
|
124 |
#define OSTREAM_DEF( NAME, SBUF, TIE, EXTRA_FLAGS )\
|
|
|
125 |
extern "C" _fake_ostream NAME = { { &NAME.base, 0 }, .... } ;
|
|
|
126 |
|
|
|
127 |
#define ISTREAM_DEF( NAME, SBUF, TIE, EXTRA_FLAGS )\
|
|
|
128 |
extern "C" _fake_istream NAME = { { &NAME.base, 0, 0 }, .... } ;
|
|
|
129 |
</PRE>
|
|
|
130 |
Note that these are declared with C linkage as above.
|
|
|
131 |
</P>
|
|
|
132 |
<P>
|
|
|
133 |
In <CODE>stdstrbufs.cc</CODE>, the <A HREF="lib.html#other">correct
|
|
|
134 |
definitions</A> for the virtual function table names are as follows:
|
|
|
135 |
<PRE>
|
|
|
136 |
#define filebuf_vtable __vt__7filebuf
|
|
|
137 |
#define stdiobuf_vtable __vt__8stdiobuf
|
|
|
138 |
</PRE>
|
|
|
139 |
Note that the <CODE>_G_VTABLE_LABEL_PREFIX</CODE> macro is incorrectly
|
|
|
140 |
defined by the configuration process (it should be <CODE>__vt__</CODE>),
|
|
|
141 |
but the <CODE>##</CODE> directives in which it is used don't work
|
|
|
142 |
on an ISO compliant preprocessor anyway (token concatenation takes
|
|
|
143 |
place after replacement of macro parameters, but before further macro
|
|
|
144 |
expansion). The dummy virtual function tables should also be declared
|
|
|
145 |
with C linkage to suppress name mangling.
|
|
|
146 |
</P>
|
|
|
147 |
In addition, the initialisation of the standard streams relies on
|
|
|
148 |
the file pointers <CODE>stdout</CODE> etc. being constant expressions,
|
|
|
149 |
which in general they are not. The directive:
|
|
|
150 |
<PRE>
|
|
|
151 |
#pragma TenDRA++ rvalue token as const allow
|
|
|
152 |
</PRE>
|
|
|
153 |
will cause the C++ producer to assume that all <A HREF="token.html#exp">
|
|
|
154 |
tokenised rvalue expressions</A> are constant.
|
|
|
155 |
<P>
|
|
|
156 |
In <CODE>streambuf.cc</CODE>, if <CODE>errno</CODE> is to be explicitly
|
|
|
157 |
declared it should have C linkage or be declared in the <CODE>std</CODE>
|
|
|
158 |
namespace.
|
|
|
159 |
</P>
|
|
|
160 |
<P>
|
|
|
161 |
In <CODE>iomanip.cc</CODE>, the explicit template instantiations should
|
|
|
162 |
be prefixed by <CODE>template</CODE>. The corresponding template
|
|
|
163 |
declarations in <CODE>iomanip.h</CODE> should be declared using
|
|
|
164 |
<A HREF="pragma.html#template"><CODE>export</CODE></A> (note that
|
|
|
165 |
the <CODE>__GNUG__</CODE> version uses <CODE>extern</CODE>, which
|
|
|
166 |
may yet win out over <CODE>export</CODE>).
|
|
|
167 |
</P>
|
|
|
168 |
|
|
|
169 |
<HR>
|
|
|
170 |
<P><I>Part of the <A HREF="../index.html">TenDRA Web</A>.<BR>Crown
|
|
|
171 |
Copyright © 1998.</I></P>
|
|
|
172 |
</BODY>
|
|
|
173 |
</HTML>
|