Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/more/microsoft_vcpp.html @ 18

Last change on this file since 18 was 12, checked in by landauf, 17 years ago

added boost

File size: 8.4 KB
Line 
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
4<title>Portability Hints: Microsoft Visual C++ 6.0 SP4</title>
5</head>
6
7<body bgcolor="#FFFFFF" text="#000000">
8
9<table border="1" bgcolor="#007F7F" cellpadding="2">
10  <tr>
11    <td bgcolor="#FFFFFF"><img src="../boost.png" alt="boost.png (6897 bytes)" width="277" height="86"></td>
12    <td><a href="../index.htm"><font face="Arial,Helvetica" color="#FFFFFF"><big>Home</big></font></a></td>
13    <td><a href="../libs/libraries.htm"><font face="Arial,Helvetica" color="#FFFFFF"><big>Libraries</big></font></a></td>
14    <td><a href="../people/people.htm"><font face="Arial,Helvetica" color="#FFFFFF"><big>People</big></font></a></td>
15    <td><a href="faq.htm"><font face="Arial,Helvetica" color="#FFFFFF"><big>FAQ</big></font></a></td>
16    <td><a href="index.htm"><font face="Arial,Helvetica" color="#FFFFFF"><big>More</big></font></a></td>
17  </tr>
18</table>
19
20<p>
21
22<h1>Portability Hints: Microsoft Visual C++ 6.0 SP4</h1>
23
24Similar to the
25<a href="borland_cpp.html">portability hints for Borland C++</a>,
26this page provides hints on some language features of the Microsoft Visual C++
27version 6.0 service pack 4 compiler.  A list of
28acknowledged deficiencies can be found at the
29<a href="http://support.microsoft.com/support/kb/articles/q243/4/51.asp">Microsoft support site</a>.
30<p>
31
32Each entry in the following list describes a particular issue,
33complete with sample source code to demonstrate the effect.
34Most sample code herein has been verified to compile with gcc 2.95.2
35and Comeau C++ 4.2.44.
36
37
38<h2>Preprocessor symbol</h2>
39
40The preprocessor symbol <code>_MSC_VER</code> is defined for all
41Microsoft C++ compilers.  Its value is the internal version number of the
42compiler interpreted as a decimal number.  Since a few other compilers
43also define this symbol, boost provides the symbol
44<code>BOOST_MSVC</code>, which is defined in
45<a href="../boost/config.hpp">boost/config.hpp</a>
46to the value of _MSC_VER if and only if the compiler is really
47Microsoft Visual C++.
48
49The following table lists some known values.
50<p>
51
52<table border="1">
53<tr>
54<th>Compiler</th>
55<th><code>BOOST_MSVC</code> value</th>
56</tr>
57
58<tr>
59<td>Microsoft Visual C++ 6.0 (up to SP4)</td>
60<td>1200</td>
61</tr>
62
63</table>
64
65
66<h2>Core Language</h2>
67
68<h3>[chained using] Chaining <code>using</code>-declarations</h3>
69
70Chaining <code>using</code>-declarations does not work.
71<pre>
72void f();
73
74namespace N {
75  using ::f;
76}
77
78void g()
79{
80  using N::f;  // C2873: 'f': the symbol cannot be used in a using-declaration
81}
82</pre>
83
84
85<h3>[explicit-instantiation] Explicit function template
86instantiation</h3>
87
88Trying to explicitly instantiate a function template leads to the
89wrong function being called silently.
90
91<pre>
92#include &lt;stdio.h&gt;
93
94template&lt;class T&gt;
95void f()
96{
97  printf(&quot;%d\n&quot;, sizeof(T));
98}
99
100int main()
101{
102  f&lt;double&gt;();      // output: &quot;1&quot;
103  f&lt;char&gt;();        // output: &quot;1&quot;
104  return 0;
105}
106</pre>
107
108
109<h3>[for-scoping] Scopes of definitions in for-loops</h3>
110
111The scope of variable definitions in <code>for</code> loops should be
112local to the loop's body, but it is instead local to the enclosing
113block.
114
115
116<pre>
117int main()
118{
119  for(int i = 0; i &lt; 5; ++i)
120   ;
121  for(int i = 0; i &lt; 5; ++i)  // C2374: 'i': Redefinition; multiple initialization
122   ;
123  return 0;
124}
125</pre>
126
127<strong>Workaround:</strong> Enclose the offending <code>for</code>
128loops in another pair of curly braces.
129<p>
130Another possible workaround (brought to my attention by Vesa Karvonen)
131is this:
132<pre>
133#ifndef for
134#define for if (0) {} else for
135#endif
136</pre>
137
138Note that platform-specific inline functions in included headers might
139depend on the old-style <code>for</code> scoping.
140
141
142<h3>[inclass-member-init] In-class member initialization</h3>
143
144In-class member initialization, required to implement a
145Standard-conforming <code>std::numeric_limits</code> template, does
146not work.
147
148<pre>
149struct A
150{
151  static const int i = 5;      // &quot;invalid syntax for pure virtual method&quot;
152};
153</pre>
154
155<strong>Workaround:</strong> Either use an enum (which has incorrect
156type, but can be used in compile-time constant expressions), or define
157the value out-of-line (which allows for the correct type, but prohibits
158using the constant in compile-time constant expressions).  See
159<a href="int_const_guidelines.htm">Coding Guidelines for Integral Constant Expressions</a>
160for guidelines how to define member constants portably in boost
161libraries.
162
163
164<h3>[koenig-lookup] Argument-dependent lookup</h3>
165
166Argument-dependent lookup, also called Koenig lookup, works for
167overloaded operators, but not for ordinary functions.  No
168additional namespaces induced from the argument types seem to be
169considered. 
170
171<pre>
172namespace N {
173  struct A {};
174  void f(A);
175}
176
177void g()
178{
179  N::A a;
180  f(a);     // 'f': undeclared identifier
181}
182</pre>
183
184
185<h3>[template-friend] Templates as friends</h3>
186
187A Template cannot be declared a friend of a class.
188
189<pre>
190template&lt;class T&gt;
191struct A {};
192
193struct B
194{
195  template&lt;class T&gt;
196  friend struct A;     // &quot;syntax error&quot;
197};
198</pre>
199
200
201<h3>[member-template-outofline] Out-of-line definitions of member
202templates</h3>
203
204Defining member templates outside their enclosing class does not work.
205
206<pre>
207template&lt;class T&gt;
208struct A
209{
210  template&lt;class U&gt;
211  void f();
212};
213
214template&lt;class T&gt;
215template&lt;class U&gt;   // &quot;syntax error&quot;
216void A&lt;T&gt;::f()      // &quot;T: undeclared identifier&quot;
217{
218}
219</pre>
220
221<strong>Workaround:</strong> Define member templates in-line within
222their enclosing class.
223
224
225<h3>[partial-spec] Partial specialization</h3>
226
227Partial specialization of class templates does not work.
228
229<pre>
230template&lt;class T&gt;
231struct A {};
232
233template&lt;class T&gt;
234struct B {};
235
236template&lt;class T&gt;
237struct A&lt;B&lt;T&gt; &gt; {};  // template class was already defined as a non-template
238</pre>
239
240<strong>Workaround:</strong> In some situations where interface
241does not matter, class member templates can simulate partial
242specialization.
243
244
245<h3>[template-value] Dependent template value parameters</h3>
246
247Template value parameters whose type depends on a previous template
248parameter provoke an internal compiler error if the correct syntax
249(with "typename") is used.
250
251<pre>
252template&lt;class T, typename T::result_type&gt; // C1001: INTERNAL COMPILER ERROR: msc1.cpp, line 1794
253struct B {};
254 // (omit &quot;typename&quot; and it compiles)
255
256</pre>
257
258<strong>Workaround:</strong> Leave off the "typename" keyword.  That makes
259the program non-conforming, though.
260
261
262<h3>[wchar_t] <code>wchar_t</code> is not built-in</h3>
263
264The type <code>wchar_t</code> is not a built-in type.
265
266<pre>
267wchar_t x;  // &quot;missing storage class or type identifier&quot;
268</pre>
269
270<strong>Workaround:</strong> When using Microsoft Visual C++, the
271header
272<a href="../boost/config.hpp">boost/config.hpp</a>
273includes <code>&lt;cstddef></code>, which defines
274<code>wchar_t</code> as a typedef for <code>unsigned
275short</code>. Note that this means that the compiler does not regard
276<code>wchar_t</code> and <code>unsigned short</code> as distinct
277types, as is required by the standard, and so ambiguities may emanate
278when overloading on <code>wchar_t</code>.  The macro
279<code>BOOST_NO_INTRINSIC_WCHAR_T</code> is defined in this situation.
280
281
282<h3>[delete-const-pointer] Deleting <code>const X *</code> does not work</h3>
283
284Trying to delete a pointer to a cv-qualified type gives an error:
285<pre>
286void f()
287{
288  const int *p = new int(5);
289  delete p;        // C2664: cannot convert from "const int *" to "void *"
290}
291</pre>
292
293<strong>Workaround:</strong> Define the function
294<pre>
295inline void operator delete(const void *p) throw()
296{ operator delete(const_cast&lt;void*>(p)); }
297</pre>
298and similar functions for the other cv-qualifier combinations, for
299operator delete[], and for the <code>std::nothrow</code> variants.
300
301
302
303<h2>Standard Library</h2>
304
305<h3>[clib-namespace] C library names in global namespace instead of std</h3>
306<p>Library names from the &lt;c...&gt; headers are in the global namespace
307instead of namespace std.<p><b>Workaround:</b>&nbsp; The header <a href="../libs/config/config.htm">boost/config.hpp</a>
308will define BOOST_NO_STDC_NAMESPACE. It can be used as follows:
309<pre># ifdef BOOST_NO_STDC_NAMESPACE
310    namespace std { using ::abs; using ::fabs; }
311# endif</pre>
312<p>Because std::size_t and std::ptrdiff_t are so commonly used, the workaround
313for these is already provided in boost/config.hpp.<p>&nbsp;
314<hr>
315
3162001-05-04 <a href="../people/jens_maurer.htm">Jens Maurer</a>
317</body>
318</html>
Note: See TracBrowser for help on using the repository browser.