1 <!DOCTYPE html PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN">
5 <meta http-equiv=
"Content-Language" content=
"en-us">
6 <meta http-equiv=
"Content-Type" content=
"text/html; charset=us-ascii">
8 <title>Portability Hints: Microsoft Visual C++
6.0 SP4
</title>
11 <body bgcolor=
"#FFFFFF" text=
"#000000">
12 <table border=
"1" bgcolor=
"#007F7F" cellpadding=
"2" summary=
"">
14 <td bgcolor=
"#FFFFFF"><img src=
"../boost.png" alt=
15 "boost.png (6897 bytes)" width=
"277" height=
"86"></td>
17 <td><a href=
"../index.htm"><font face=
"Arial,Helvetica" color=
18 "#FFFFFF"><big>Home
</big></font></a></td>
20 <td><a href=
"../libs/libraries.htm"><font face=
"Arial,Helvetica" color=
21 "#FFFFFF"><big>Libraries
</big></font></a></td>
23 <td><a href=
"../people/people.htm"><font face=
"Arial,Helvetica" color=
24 "#FFFFFF"><big>People
</big></font></a></td>
26 <td><a href=
"faq.htm"><font face=
"Arial,Helvetica" color=
27 "#FFFFFF"><big>FAQ
</big></font></a></td>
29 <td><a href=
"index.htm"><font face=
"Arial,Helvetica" color=
30 "#FFFFFF"><big>More
</big></font></a></td>
34 <h1>Portability Hints: Microsoft Visual C++
6.0 SP4
</h1>
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
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>
47 <h2>Preprocessor symbol
</h2>
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>
57 <table border=
"1" summary=
"">
61 <th><code>BOOST_MSVC
</code> value
</th>
65 <td>Microsoft Visual C++
6.0 (up to SP6)
</td>
71 <td>Microsoft embedded Visual C++
4.0</td>
73 <td>1200-
1202 (cross compilers)
</td>
77 <h2>Core Language
</h2>
79 <h3>[chained using] Chaining
<code>using
</code>-declarations
</h3>
81 <p>Chaining
<code>using
</code>-declarations does not work.
</p>
91 using N::f; // C2873: 'f': the symbol cannot be used in a using-declaration
95 <h3>[explicit-instantiation] Explicit function template instantiation
</h3>
97 <p>Trying to explicitly instantiate a function template leads to the wrong
98 function being called silently.
</p>
100 #include
<stdio.h
>
102 template
<class T
>
105 printf(
"%d\n", sizeof(T));
110 f
<double
>(); // output:
"1"
111 f
<char
>(); // output:
"1"
116 <h3>[for-scoping] Scopes of definitions in for-loops
</h3>
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
124 for(int i =
0; i
< 5; ++i)
126 for(int i =
0; i
< 5; ++i) // C2374: 'i': Redefinition; multiple initialization
132 <p><strong>Workaround:
</strong> Enclose the offending
<code>for
</code>
133 loops in another pair of curly braces.
</p>
135 <p>Another possible workaround (brought to my attention by Vesa Karvonen)
139 #define for if (
0) {} else for
143 <p>Note that platform-specific inline functions in included headers might
144 depend on the old-style
<code>for
</code> scoping.
</p>
146 <h3>[inclass-member-init] In-class member initialization
</h3>
148 <p>In-class member initialization, required to implement a
149 Standard-conforming
<code>std::numeric_limits
</code> template, does not
154 static const int i =
5; //
"invalid syntax for pure virtual method"
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
166 <h3>[koenig-lookup] Argument-dependent lookup
</h3>
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>
180 f(a); // 'f': undeclared identifier
184 <h3>[template-friend] Templates as friends
</h3>
186 <p>A Template cannot be declared a friend of a class.
</p>
188 template
<class T
>
193 template
<class T
>
194 friend struct A; //
"syntax error"
198 <h3>[member-template-outofline] Out-of-line definitions of member
201 <p>Defining member templates outside their enclosing class does not
204 template
<class T
>
207 template
<class U
>
211 template
<class T
>
212 template
<class U
> //
"syntax error"
213 void A
<T
>::f() //
"T: undeclared identifier"
218 <p><strong>Workaround:
</strong> Define member templates in-line within
219 their enclosing class.
</p>
221 <h3>[partial-spec] Partial specialization
</h3>
223 <p>Partial specialization of class templates does not work.
</p>
225 template
<class T
>
228 template
<class T
>
231 template
<class T
>
232 struct A
<B
<T
> > {}; // template class was already defined as a non-template
235 <p><strong>Workaround:
</strong> In some situations where interface does not
236 matter, class member templates can simulate partial specialization.
</p>
238 <h3>[template-value] Dependent template value parameters
</h3>
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>
244 template
<class T, typename T::result_type
> // C1001: INTERNAL COMPILER ERROR: msc1.cpp, line
1794
246 // (omit
"typename" and it compiles)
250 <p><strong>Workaround:
</strong> Leave off the
"typename" keyword. That
251 makes the program non-conforming, though.
</p>
253 <h3>[wchar_t]
<code>wchar_t
</code> is not built-in
</h3>
255 <p>The type
<code>wchar_t
</code> is not a built-in type.
</p>
257 wchar_t x; //
"missing storage class or type identifier"
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><cstddef
></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>
269 <h3>[delete-const-pointer] Deleting
<code>const X *
</code> does not
272 <p>Trying to delete a pointer to a cv-qualified type gives an error:
</p>
276 const int *p = new int(
5);
277 delete p; // C2664: cannot convert from
"const int *" to
"void *"
281 <p><strong>Workaround:
</strong> Define the function
</p>
283 inline void operator delete(const void *p) throw()
284 { operator delete(const_cast
<void*
>(p)); }
287 <p>and similar functions for the other cv-qualifier combinations, for
288 operator delete[], and for the
<code>std::nothrow
</code> variants.
</p>
290 <h2>Standard Library
</h2>
292 <h3>[clib-namespace] C library names in global namespace instead of
295 <p>Library names from the
<c...
> headers are in the global namespace
296 instead of namespace std.
</p>
298 <p><b>Workaround:
</b> 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>
302 # ifdef BOOST_NO_STDC_NAMESPACE
303 namespace std { using ::abs; using ::fabs; }
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>
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>
316 <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->04 December,
2006<!--webbot bot="Timestamp" endspan i-checksum="38514" --></p>
318 <p><i>Copyright
© 2001-
2002 <a href=
"../people/jens_maurer.htm">Jens
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
324 "http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt
</a>)
</i></p>