Skip to content
Navigation Menu
{{ message }}
forked from boostorg/website
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathborland_cpp.html
More file actions
426 lines (344 loc) · 13.4 KB
/
Copy pathborland_cpp.html
File metadata and controls
426 lines (344 loc) · 13.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Portability Hints: Borland C++ 5.5.1</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="icon" href="/favicon.ico" type="image/ico" />
<link rel="stylesheet" type="text/css" href=
"/style-v2/section-development.css" />
<!--[if IE 7]> <style type="text/css"> body { behavior: url(/style-v2/csshover3.htc); } </style> <![endif]-->
</head><!--
Note: Editing website content is documented at:
https://www.boost.org/development/website_updating.html
-->
<body>
<div id="heading">
<!--#include virtual="/common/heading.html" -->
</div>
<div id="body">
<div id="body-inner">
<div id="content">
<div class="section" id="intro">
<div class="section-0">
<div class="section-title">
<h1>Portability Hints: Borland C++ 5.5.1</h1>
</div>
<div class="section-body">
<p>It is a general aim for boost libraries to be <a href=
"/development/requirements.html#Portability">portable</a>. The
primary means for achieving this goal is to adhere to ISO
Standard C++. However, ISO C++ is a broad and complex standard
and most compilers are not fully conformant to ISO C++ yet. In
order to achieve portability in the light of this restriction,
it seems advisable to get acquainted with those language
features that some compilers do not fully implement yet.</p>
<p>This page gives portability hints on some language features
of the Borland C++ version 5.5.1 compiler. Furthermore, the
appendix presents additional problems with Borland C++ version
5.5. Borland C++ 5.5.1 is a freely available command-line
compiler for Win32 available at <a href=
"http://www.borland.com/">http://www.borland.com/</a>.</p>
<p>Each entry in the following list describes a particular
issue, complete with sample source code to demonstrate the
effect. Most sample code herein has been verified to compile
with gcc 2.95.2 and Comeau C++ 4.2.44.</p>
<h2>Preprocessor symbol</h2>
<p>The preprocessor symbol <code>__BORLANDC__</code> is defined
for all Borland C++ compilers. Its value is the version number
of the compiler interpreted as a hexadecimal number. The
following table lists some known values.</p>
<table border="1" summary="">
<tr>
<th>Compiler</th>
<th><code>__BORLANDC__</code> value</th>
</tr>
<tr>
<td>Borland C++ Builder 4</td>
<td>0x0540</td>
</tr>
<tr>
<td>Borland C++ Builder 5</td>
<td>0x0550</td>
</tr>
<tr>
<td>Borland C++ 5.5</td>
<td>0x0550</td>
</tr>
<tr>
<td>Borland C++ 5.5.1</td>
<td>0x0551</td>
</tr>
<tr>
<td>Borland C++ Builder 6</td>
<td>0x0560</td>
</tr>
</table>
<h2>Core Language</h2>
<h3>[using-directive] Mixing <code>using</code>-declarations
and <code>using</code>-directives</h3>
<p>Mixing <code>using</code>-directives (which refer to whole
namespaces) and namespace-level <code>using</code>-declarations
(which refer to individual identifiers within foreign
namespaces) causes ambiguities where there are none. The
following code fragment illustrates this:</p>
<pre>
namespace N {
int x();
}
using N::x;
using namespace N;
int main()
{
&x; // Ambiguous overload
}
</pre>
<h3>[using template] <code>using</code>-declarations for class
templates</h3>
<p>Identifiers for class templates can be used as arguments to
<code>using</code>-declarations as any other identifier.
However, the following code fails to compile with Borland
C++:</p>
<pre>
template<class T>
class X { };
namespace N
{
// "cannot use template 'X<T>' without specifying specialization parameters"
using ::X;
};
</pre>
<h3>[template const arg] Deduction of constant arguments to
function templates</h3>
<p>Template function type deduction should omit top-level
constness. However, this code fragment instantiates "f<const
int>(int)":</p>
<pre>
template<class T>
void f(T x)
{
x = 1; // works
(void) &x;
T y = 17;
y = 20; // "Cannot modify a const object in function f<const int>(int)"
(void) &y;
}
int main()
{
const int i = 17;
f(i);
}
</pre>
<h3>[function address] Resolving addresses of overloaded
functions</h3>
<p>Addresses of overloaded functions are not in all contexts
properly resolved (std:13.4 [over.over]); here is a small
example:</p>
<pre>
template<class Arg>
void f( void(*g)(Arg) );
void h(int);
void h(double);
template<class T>
void h2(T);
int main()
{
void (*p)(int) = h; // this works (std:13.4-1.1)
void (*p2)(unsigned char) = h2; // this works as well (std:13.4-1.1)
f<int>(h2); // this also works (std:13.4-1.3)
// "Cannot generate template specialization from h(int)",
// "Could not find a match for f<Arg>(void (*)(int))"
f<double>(h); // should work (std:13.4-1.3)
f( (void(*)(double))h); // C-style cast works (std:13.4-1.6 with 5.4)
// "Overloaded 'h' ambiguous in this context"
f(static_cast<void(*)(double)>(h)); // should work (std:13.4-1.6 with 5.2.9)
}
</pre>
<p><strong>Workaround:</strong> Always use C-style casts when
determining addresses of (potentially) overloaded
functions.</p>
<h3>[string conversion] Converting <code>const char *</code> to
<code>std::string</code></h3>
<p>Implicitly converting <code>const char *</code> parameters
to <code>std::string</code> arguments fails if template
functions are explicitly instantiated (it works in the usual
cases, though):</p>
<pre>
#include <string>
template<class T>
void f(const std::string & s)
{}
int main()
{
f<double>("hello"); // "Could not find a match for f<T>(char *)"
}
</pre>
<p><strong>Workaround:</strong> Avoid explicit template
function instantiations (they have significant problems with
Microsoft Visual C++) and pass default-constructed unused dummy
arguments with the appropriate type. Alternatively, if you wish
to keep to the explicit instantiation, you could use an
explicit conversion to <code>std::string</code> or declare the
template function as taking a <code>const char *</code>
parameter.</p>
<h3>[template value defaults] Dependent default arguments for
template value parameters</h3>
<p>Template value parameters which default to an expression
dependent on previous template parameters don't work:</p>
<pre>
template<class T>
struct A
{
static const bool value = true;
};
// "Templates must be classes or functions", "Declaration syntax error"
template<class T, bool v = A<T>::value>
struct B {};
int main()
{
B<int> x;
}
</pre>
<p><strong>Workaround:</strong> If the relevant non-type
template parameter is an implementation detail, use inheritance
and a fully qualified identifier (for example,
::N::A<T>::value).</p>
<h3>[function partial ordering] Partial ordering of function
templates</h3>
<p>Partial ordering of function templates, as described in
std:14.5.5.2 [temp.func.order], does not work:</p>
<pre>
#include <iostream>
template<class T> struct A {};
template<class T1>
void f(const A<T1> &)
{
std::cout << "f(const A<T1>&)\n";
}
template<class T>
void f(T)
{
std::cout << "f(T)\n";
}
int main()
{
A<double> a;
f(a); // output: f(T) (wrong)
f(1); // output: f(T) (correct)
}
</pre>
<p><strong>Workaround:</strong> Declare all such functions
uniformly as either taking a value or a reference
parameter.</p>
<h3>[instantiate memfun ptr] Instantiation with member function
pointer</h3>
<p>When directly instantiating a template with some member
function pointer, which is itself dependent on some template
parameter, the compiler cannot cope:</p>
<pre>
template<class U> class C { };
template<class T>
class A
{
static const int v = C<void (T::*)()>::value;
};
</pre>
<p><strong>Workaround:</strong> Use an intermediate
<code>typedef</code>:</p>
<pre>
template<class U> class C { };
template<class T>
class A
{
typedef void (T::*my_type)();
static const int v = C<my_type>::value;
};
</pre>
<p>(Extracted from e-mail exchange of David Abrahams, Fernando
Cacciola, and Peter Dimov; not actually tested.)</p>
<h2>Library</h2>
<h3>[cmath.abs] Function <code>double std::abs(double)</code>
missing</h3>
<p>The function <code>double std::abs(double)</code> should be
defined (std:26.5-5 [lib.c.math]), but it is not:</p>
<pre>
#include <cmath>
int main()
{
double (*p)(double) = std::abs; // error
}
</pre>
<p>Note that <code>int std::abs(int)</code> will be used
without warning if you write <code>std::abs(5.1)</code>.</p>
<p>Similar remarks apply to seemingly all of the other standard
math functions, where Borland C++ fails to provide
<code>float</code> and <code>long double</code> overloads.</p>
<p><strong>Workaround:</strong> Use <code>std::fabs</code>
instead if type genericity is not required.</p>
<h2>Appendix: Additional issues with Borland C++ version
5.5</h2>
<p>These issues are documented mainly for historic reasons. If
you are still using Borland C++ version 5.5, you are strongly
encouraged to obtain an upgrade to version 5.5.1, which fixes
the issues described in this section.</p>
<h3>[inline friend] Inline friend functions in template
classes</h3>
<p>If a friend function of some class has not been declared
before the friend function declaration, the function is
declared at the namespace scope surrounding the class
definition. Together with class templates and inline
definitions of friend functions, the code in the following
fragment should declare (and define) a non-template function
"bool N::f(int,int)", which is a friend of class
N::A<int>. However, Borland C++ v5.5 expects the function
f to be declared beforehand:</p>
<pre>
namespace N {
template<class T>
class A
{
// "f is not a member of 'N' in function main()"
friend bool f(T x, T y) { return x < y; }
};
}
int main()
{
N::A<int> a;
}
</pre>
<p>This technique is extensively used in boost/operators.hpp.
Giving in to the wish of the compiler doesn't work in this
case, because then the "instantiate one template, get lots of
helper functions at namespace scope" approach doesn't work
anymore. Defining BOOST_NO_OPERATORS_IN_NAMESPACE (a define
BOOST_NO_INLINE_FRIENDS_IN_CLASS_TEMPLATES would match this
case better) works around this problem and leads to another
one, see [using-template].</p>
</div>
</div>
</div>
</div>
<div id="sidebar">
<!--#include virtual="/common/sidebar-common.html" -->
<!--#include virtual="/common/sidebar-development.html" -->
</div>
<div class="clear"></div>
</div>
</div>
<div id="footer">
<div id="footer-left">
<div id="revised">
<p>Revised $Date: 2007-10-22 22:55:52 +0100 (Mon, 22 Oct 2007) $</p>
</div>
<div id="copyright">
<p>Copyright © 2000-2002 <a href=
"/users/people/jens_maurer.html">Jens Maurer</a></p>
</div><!--#include virtual="/common/footer-license.html" -->
</div>
<div id="footer-right">
<!--#include virtual="/common/footer-banners.html" -->
</div>
<div class="clear"></div>
</div>
</body>
</html>
You can’t perform that action at this time.
