microsoft_vcpp.html 6.3 KB

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