microsoft_vcpp.html 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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. <body bgcolor="#FFFFFF" text="#000000">
  7. <table border="1" bgcolor="#007F7F" cellpadding="2">
  8. <tr>
  9. <td bgcolor="#FFFFFF"><img src="../c++boost.gif" alt="c++boost.gif (8819 bytes)" width="277" height="86"></td>
  10. <td><a href="../index.htm"><font face="Arial,Helvetica" color="#FFFFFF"><big>Home</big></font></a></td>
  11. <td><a href="../libs/libraries.htm"><font face="Arial,Helvetica" color="#FFFFFF"><big>Libraries</big></font></a></td>
  12. <td><a href="../people/people.htm"><font face="Arial,Helvetica" color="#FFFFFF"><big>People</big></font></a></td>
  13. <td><a href="faq.htm"><font face="Arial,Helvetica" color="#FFFFFF"><big>FAQ</big></font></a></td>
  14. <td><a href="index.htm"><font face="Arial,Helvetica" color="#FFFFFF"><big>More</big></font></a></td>
  15. </tr>
  16. </table>
  17. <p>
  18. <h1>Portability Hints: Microsoft Visual C++ 6.0 SP4</h1>
  19. Similar to the
  20. <a href="borland_cpp.html">portability hints for Borland C++</a>,
  21. this page provides hints on some language features of the Microsoft Visual C++
  22. version 6.0 service pack 4 compiler. A list of
  23. acknowledged deficiencies can be found at the
  24. <a href="http://support.microsoft.com/support/kb/articles/q243/4/51.asp">Microsoft support site</a>.
  25. <p>
  26. Each entry in the following list describes a particular issue,
  27. complete with sample source code to demonstrate the effect.
  28. Most sample code herein has been verified to compile with gcc 2.95.2
  29. and Comeau C++ 4.2.44.
  30. <h2>Preprocessor symbol</h2>
  31. The preprocessor symbol <code>_MSC_VER</code> is defined for all
  32. Microsoft C++ compilers. Its value is the internal version number of the
  33. compiler interpreted as a decimal number. Since a few other compilers
  34. also define this symbol, boost provides the symbol
  35. <code>BOOST_MSVC</code> defined in
  36. <a href="../boost/config.hpp">boost/config.hpp</a>
  37. to the value of _MSC_VER if and only if the compiler is really
  38. Microsoft Visual C++.
  39. The following table lists some known values.
  40. <p>
  41. <table border="1">
  42. <tr>
  43. <th>Compiler</th>
  44. <th><code>BOOST_MSVC</code> value</th>
  45. </tr>
  46. <tr>
  47. <td>Microsoft Visual C++ 6.0 SP4</td>
  48. <td>1200</td>
  49. </tr>
  50. </table>
  51. <h2>Core Language</h2>
  52. <h3>[chained using] Chaining <code>using</code>-declarations</h3>
  53. Chaining <code>using</code>-declarations do not work.
  54. <pre>
  55. void f();
  56. namespace N {
  57. using ::f;
  58. }
  59. void g()
  60. {
  61. using N::f; // C2873: 'f': the symbol cannot be used in a using-declaration
  62. }
  63. </pre>
  64. <h3>[explicit-instantiation] Explicit function template
  65. instantiation</h3>
  66. Trying to explicitly instantiate a function template leads to the
  67. wrong function being called silently.
  68. <pre>
  69. #include &lt;stdio.h&gt;
  70. template&lt;class T&gt;
  71. void f()
  72. {
  73. printf(&quot;%d\n&quot;, sizeof(T));
  74. }
  75. int main()
  76. {
  77. f&lt;double&gt;(); // output: &quot;1&quot;
  78. f&lt;char&gt;(); // output: &quot;1&quot;
  79. return 0;
  80. }
  81. </pre>
  82. <h3>[for-scoping] Scopes of definitions in for-loops</h3>
  83. The scope of variable definitions in <code>for</code> loops should be
  84. local to the loop's body, but it is instead local to the enclosing
  85. block.
  86. <pre>
  87. int main()
  88. {
  89. for(int i = 0; i &lt; 5; ++i)
  90. ;
  91. for(int i = 0; i &lt; 5; ++i) // C2374: 'i': Redefinition; multiple initialization
  92. ;
  93. return 0;
  94. }
  95. </pre>
  96. <strong>Workaround:</strong> Enclose the offending <code>for</code>
  97. loops in another pair of curly braces.
  98. <h3>[inclass-member-init] In-class member initialization</h3>
  99. In-class member initialization, require to implement a
  100. Standard-conforming <code>std::numeric_limits</code> template, does
  101. not work.
  102. <pre>
  103. struct A
  104. {
  105. static const int i = 5; // &quot;invalid syntax for pure virtual method&quot;
  106. };
  107. </pre>
  108. <h3>[koenig-lookup] Argument-dependent lookup</h3>
  109. Argument-dependent lookup, also called Koenig lookup, does not work.
  110. No additional namespaces induced from the argument types seem to be
  111. considered.
  112. <pre>
  113. namespace N {
  114. struct A {};
  115. void f(A);
  116. }
  117. void g()
  118. {
  119. N::A a;
  120. f(a); // 'f': undeclared identifier
  121. }
  122. </pre>
  123. <h3>[template-friend] Templates as friends</h3>
  124. A Template cannot be declared a friend of a class.
  125. <pre>
  126. template&lt;class T&gt;
  127. struct A {};
  128. struct B
  129. {
  130. template&lt;class T&gt;
  131. friend struct A; // &quot;syntax error&quot;
  132. };
  133. </pre>
  134. <h3>[member-template-outofline] Out-of-line definitions of member
  135. templates</h3>
  136. Defining member templates outside their enclosing class does not work.
  137. <pre>
  138. template&lt;class T&gt;
  139. struct A
  140. {
  141. template&lt;class U&gt;
  142. void f();
  143. };
  144. template&lt;class T&gt;
  145. template&lt;class U&gt; // &quot;syntax error&quot;
  146. void A&lt;T&gt;::f() // &quot;T: undeclared identifier&quot;
  147. {
  148. }
  149. </pre>
  150. <strong>Workaround:</strong> Define member templates in-line within
  151. their enclosing class.
  152. <h3>[partial-spec] Partial specialization</h3>
  153. Partial specialization of class templates does not work.
  154. <pre>
  155. template&lt;class T&gt;
  156. struct A {};
  157. template&lt;class T&gt;
  158. struct B {};
  159. template&lt;class T&gt;
  160. struct A&lt;B&lt;T&gt; &gt; {}; // template class was already defined as a non-template
  161. </pre>
  162. <strong>Workaround:</strong> In some situations where interface
  163. does not matter, member class templates can simulate partial
  164. specialization.
  165. <h3>[template-value] Dependent template value parameters</h3>
  166. Template value parameters whose type depends on a previous template
  167. parameter provoke an internal compiler error if the correct syntax
  168. (with "typename") is used.
  169. <pre>
  170. template&lt;class T, typename T::result_type&gt; // C1001: INTERNAL COMPILER ERROR: msc1.cpp, line 1794
  171. struct B {};
  172. // (omit &quot;typename&quot; and it compiles)
  173. </pre>
  174. <h3>[wchar_t] <code>wchar_t</code> is not built-in</h3>
  175. The type <code>wchar_t</code> is not a built-in type.
  176. <pre>
  177. wchar_t x; // &quot;missing storage class or type identifier&quot;
  178. </pre>
  179. <strong>Workaround:</strong> The header <code>&lt;cstddef></code>
  180. provides a typedef for <code>wchar_t</code> and
  181. <a href="../boost/config.hpp">boost/config.hpp</a>
  182. includes it to provide the workaround. Note that this is not a
  183. distinct type from any other built-in type as required by the
  184. standard, so ambiguities when overloading on <code>wchar_t</code> may
  185. emanate.
  186. <h2>
  187. Standard Library</h2>
  188. <h3>[clib-namespace] C library names in global namespace instead of std</h3>
  189. <p>Library names from the &lt;c...&gt; headers are in the global namespace
  190. instead of namespace std.<p><b>Workaround:</b>&nbsp; The header <a href="../libs/config/index.htm">boost/config.hpp</a>
  191. will define BOOST_NO_STDC_NAMESPACE. It can be used as follows:
  192. <pre># ifdef BOOST_NO_STDC_NAMESPACE
  193. namespace std { using ::abs; using ::fabs; }
  194. # endif</pre>
  195. <p>Because std::size_t and std::ptrdiff_t are so commonly used, the workaround
  196. for these is already provided in boost/config.hpp.<p>&nbsp;
  197. <hr>
  198. 2001-02-01 <a href="../people/jens_maurer.htm">Jens Maurer</a>
  199. </body>
  200. </html>
粤ICP备19079148号