Boost logo

Boost :

From: Edward Diener (eddielee_at_[hidden])
Date: 2003-06-04 16:08:32


Randy Bowen wrote:
>> A disappointing aspect of this in regards to MSVC 7.0+ is
>> that there is no preprocessor macro ( as of 7.0, I haven't
>> checked 7.1 yet ) which MSVC defines for distinguishing
>> native C++ wide character from the previous typedef for
>> wchar_t.
>
> The MS-specific macro _NATIVE_WCHAR_T_DEFINED indicates the presence
> of
> the native type in MSVC 7.0+. However, use of this can cause a number
> of problems with existing MS libraries (and especially anything that
> deals with COM).

The documentation is very confusing regarding this. First we have under
Predefined Macros:

"_WCHAR_T_DEFINED
and
_NATIVE_WCHAR_T_DEFINED

Defined when wchar_t is defined. Typically, wchar_t is defined when you use
/Zc:wchar_t or when typedef unsigned short wchar_t; is executed in code."

which implies that both the macros above are defined in both cases. Next we
have under the compiler switch "/Zc:wchar_t (wchar_t Is Native Type)":

"When /Zc:wchar_t is specified, _WCHAR_T_DEFINED and _NATIVE_WCHAR_T_DEFINED
symbols are defined; see Predefined Macros for more information."

which simply reiterates the first part of the previous topic.

Testing this out, both VC++ 7.0 and VC++ 7.1 yield the same result which
confirms what you have written above. When the /Zc:wchar_t switch is used,
both of the above macros are defined. When the /Zc:wchar_t is not used, only
the _WCHAR_T_DEFINED macro is defined.

So I was definitely wrong in thinking that there was no way to test for the
difference. Perhaps the previous documentation which I read didn't explain
the _NATIVE_WCHAR_T_DEFINED macro or perhaps I just missed it. But this is
good for Boost. Now there is a way to determine whether which of the wchar_t
types in VC++ are being used at compile time.

My suggestion for Boost is that it use library implementors use this in
order to alert the end-user at compile time that a particular usage of
wchar_t is not supported, or use it to correctly link in the correct version
of the library when both are supported. For VC++, the #pragma
comment(lib,"SomeLib") specifies the name of the library to link, either
import or static. I know John Maddock does this in Regex++ but the general
usage for our wchar_t, reiterated here, would be:

#if defined(_NATIVE_WCHAR_T_DEFINED)
#pragma comment(lib,"NativeWchartVersion.lib"
#elif defined(_WCHAR_T_DEFINED)
#pragma comment(lib,"VCWchartVersion.lib")
#endif

Of course I expect Boost may want to create BOOST_ macros for these VC++
specific macros in the correct configuration file and use them instead, but
one gets the general idea from this.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk