Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/more/microsoft_vcpp.html @ 63

Last change on this file since 63 was 29, checked in by landauf, 16 years ago

updated boost from 1_33_1 to 1_34_1

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