Using Microsoft-Specific Predefined Preprocessor Macros
A sample function that uses ANSI-Compliant Predefined Preprocessor Macros:
bool CPreprocessingDlg::UseMicrosoftSpecificPredefinedMacros(void)
{
// Using Microsoft-Specific Predefined Preprocessor Macros
// Ref: http://msdn.microsoft.com/en-us/library/b0084kay(VS.80).aspx
TCHAR buffer[MAX_PATH];
CString m_strOutput;
m_strOutput += "\r\n\r\n";
m_strOutput += "-- Microsoft-Specific Predefined Macros --";
// _ATL_VER - Defines the ATL version.
m_strOutput += "\r\n";
swprintf_s(buffer, MAX_PATH, TEXT("ATL Version: 0x%0.4X"), _ATL_VER);
m_strOutput += buffer;
// _CHAR_UNSIGNED - Default char type is unsigned. Defined when /J is specified.
m_strOutput += "\r\n";
m_strOutput += "Default char Type Is unsigned [_CHAR_UNSIGNED]: ";
#ifdef _CHAR_UNSIGNED
swprintf_s(buffer, MAX_PATH, TEXT("%s (%d)"), TEXT("YES"), _CHAR_UNSIGNED);
#else
swprintf_s(buffer, MAX_PATH, TEXT("NO"));
#endif
m_strOutput += buffer;
// __CLR_VER - Defines the version of the common language runtime used
// when the application was compiled. The value returned will be in
// the following format: Mmmbbbbb
// where,
// M is the major version of the runtime.
// mm is the minor version of the runtime.
// bbbbb is the build number.
m_strOutput += "\r\n";
m_strOutput += "Common Language Runtime Version [__CLR_VER]: ";
#ifdef __CLR_VER
swprintf_s(buffer, MAX_PATH, TEXT("%s"), __CLR_VER);
#else
swprintf_s(buffer, MAX_PATH, TEXT("UNDEFINED"));
#endif
m_strOutput += buffer;
// __cplusplus_cli - Defined when compiling with /clr, /clr:pure, or /clr:safe.
// Value of __cplusplus_cli is 200406.
// __cplusplus_cli is in effect throughout the translation unit.
m_strOutput += "\r\n";
m_strOutput += "__cplusplus_cli: ";
#ifdef __cplusplus_cli
swprintf_s(buffer, MAX_PATH, TEXT("%s (%d)"), TEXT("YES"), __cplusplus_cli);
#else
swprintf_s(buffer, MAX_PATH, TEXT("NO"));
#endif
m_strOutput += buffer;
// __cplusplus - Defined for C++ programs only.
m_strOutput += "\r\n";
m_strOutput += "C++ Program [__cplusplus]: ";
#ifdef __cplusplus
swprintf_s(buffer, MAX_PATH, TEXT("%s (%d)"), TEXT("YES"), __cplusplus);
#else
swprintf_s(buffer, MAX_PATH, TEXT("NO"));
#endif
m_strOutput += buffer;
// _CPPLIB_VER - Defined if you include any of the C++ Standard Library headers.
// Reports which version of the Dinkumware header files are present.
m_strOutput += "\r\n";
m_strOutput += "C++ Standard Library Header Version [_CPPLIB_VER]: ";
#ifdef _CPPLIB_VER
swprintf_s(buffer, MAX_PATH, TEXT("%s"), _CPPLIB_VER);
#else
swprintf_s(buffer, MAX_PATH, TEXT("UNDEFINED"));
#endif
m_strOutput += buffer;
// _CPPRTTI - Defined for code compiled with /GR (Enable Run-Time Type Information)
m_strOutput += "\r\n";
m_strOutput += "Enable Run-Time Type Information [_CPPRTTI]: ";
#ifdef _CPPRTTI
swprintf_s(buffer, MAX_PATH, TEXT("%s (%d)"), TEXT("YES"), _CPPRTTI);
#else
swprintf_s(buffer, MAX_PATH, TEXT("UNDEFINED"));
#endif
m_strOutput += buffer;
// _CPPUNWIND - Defined for code compiled with /GX (Enable Exception Handling).
m_strOutput += "\r\n";
m_strOutput += "Enable Exception Handling [_CPPUNWIND]: ";
#ifdef _CPPUNWIND
swprintf_s(buffer, MAX_PATH, TEXT("%s (%d)"), TEXT("YES"), _CPPUNWIND);
#else
swprintf_s(buffer, MAX_PATH, TEXT("UNDEFINED"));
#endif
m_strOutput += buffer;
// _DEBUG - Defined when compiling with /LDd, /MDd, and /MTd.
m_strOutput += "\r\n";
m_strOutput += "Debug Mode [_DEBUG]: ";
#ifdef _DEBUG
swprintf_s(buffer, MAX_PATH, TEXT("%s (%d)"), TEXT("YES"), _DEBUG);
#else
swprintf_s(buffer, MAX_PATH, TEXT("NO"));
#endif
m_strOutput += buffer;
// _DLL - Defined when /MD or /MDd (Multithread DLL) is specified.
m_strOutput += "\r\n";
m_strOutput += "Multithread DLL [_DLL]: ";
#ifdef _DLL
swprintf_s(buffer, MAX_PATH, TEXT("%s (%d)"), TEXT("YES"), _DLL);
#else
swprintf_s(buffer, MAX_PATH, TEXT("NO"));
#endif
m_strOutput += buffer;
// __FUNCDNAME__ - Valid only within a function and returns the decorated
// name of the enclosing function (as a string). __FUNCDNAME__ is not
// expanded if you use the /EP or /P compiler option.
m_strOutput += "\r\n";
m_strOutput += "Function name (decorated) [__FUNCDNAME__]: ";
#ifdef __FUNCDNAME__
swprintf_s(buffer, MAX_PATH, TEXT("%s"), TEXT(__FUNCDNAME__));
#else
swprintf_s(buffer, MAX_PATH, TEXT("UNDEFINED"));
#endif
m_strOutput += buffer;
// __FUNCSIG__ - Valid only within a function and returns the signature of the
// enclosing function (as a string). __FUNCSIG__ is not expanded if you use the
// /EP or /P compiler option.
m_strOutput += "\r\n";
m_strOutput += "Function signature [__FUNCSIG__]: ";
#ifdef __FUNCSIG__
swprintf_s(buffer, MAX_PATH, TEXT("%s"), TEXT(__FUNCSIG__));
#else
swprintf_s(buffer, MAX_PATH, TEXT("UNDEFINED"));
#endif
m_strOutput += buffer;
// __FUNCTION__ - Valid only within a function and returns the undecorated name of the enclosing
// function (as a string). __FUNCTION__ is not expanded if you use the /EP or /P
// compiler option.
m_strOutput += "\r\n";
m_strOutput += "Function name [__FUNCTION__]: ";
#ifdef __FUNCTION__
swprintf_s(buffer, MAX_PATH, TEXT("%s"), TEXT(__FUNCTION__));
#else
swprintf_s(buffer, MAX_PATH, TEXT("UNDEFINED"));
#endif
m_strOutput += buffer;
// _INTEGRAL_MAX_BITS - Reports the maximum size (in bits) for an integral type.
m_strOutput += "\r\n";
m_strOutput += "Integral type maximum size (in bits) [_INTEGRAL_MAX_BITS]: ";
#ifdef _INTEGRAL_MAX_BITS
swprintf_s(buffer, MAX_PATH, TEXT("%d"), _INTEGRAL_MAX_BITS);
#else
swprintf_s(buffer, MAX_PATH, TEXT("Undefined"));
#endif
m_strOutput += buffer;
// _M_ALPHA - Defined for DEC ALPHA platforms. It is defined as 1 by the ALPHA compiler, and
// it is not defined if another compiler is used.
m_strOutput += "\r\n";
m_strOutput += "DEC ALPHA Platform [_M_ALPHA]: ";
#ifdef _M_ALPHA
swprintf_s(buffer, MAX_PATH, TEXT("%s (%d)"), TEXT("YES"), _M_ALPHA);
#else
swprintf_s(buffer, MAX_PATH, TEXT("NO"));
#endif
m_strOutput += buffer;
// _M_CEE - Defined for a compilation that uses any form of /clr (/clr:oldSyntax, /clr:safe,
// for example).
m_strOutput += "\r\n";
m_strOutput += "Common Language Runtime Compilation [_M_CEE]: ";
#ifdef _M_CEE
swprintf_s(buffer, MAX_PATH, TEXT("%s (%d)"), TEXT("YES"), _M_CEE);
#else
swprintf_s(buffer, MAX_PATH, TEXT("NO"));
#endif
m_strOutput += buffer;
// _M_CEE_PURE - Defined for a compilation that uses /clr:pure.
m_strOutput += "\r\n";
m_strOutput += "Common Language Runtime Pure Compilation [_M_CEE_PURE]: ";
#ifdef _M_CEE_PURE
swprintf_s(buffer, MAX_PATH, TEXT("%s (%d)"), TEXT("YES"), _M_CEE_PURE);
#else
swprintf_s(buffer, MAX_PATH, TEXT("NO"));
#endif
m_strOutput += buffer;
// _M_CEE_SAFE - Defined for a compilation that uses /clr:safe.
m_strOutput += "\r\n";
m_strOutput += "Common Language Runtime Safe Compilation [_M_CEE_SAFE]: ";
#ifdef _M_CEE_SAFE
swprintf_s(buffer, MAX_PATH, TEXT("%s (%d)"), TEXT("YES"), _M_CEE_SAFE);
#else
swprintf_s(buffer, MAX_PATH, TEXT("NO"));
#endif
m_strOutput += buffer;
// _M_IX86 - Defined for x86 processors. See Values for _M_IX86 for more details.
// Blend: /GB: _M_IX86 = 600 (Default. Future compilers will emit a different value to reflect the dominant processor.)
// Pentium: /G5: _M_IX86 = 500
// Pentium Pro, Pentium II, and Pentium III: /G6: _M_IX86 = 600
// 80386: /G3: _M_IX86 = 300
// 80486: /G4: _M_IX86 = 400
m_strOutput += "\r\n";
m_strOutput += "Minimum CPU Architecture [_M_IX86]: ";
#ifdef _M_IX86
if (600 == _M_IX86)
swprintf_s(buffer, MAX_PATH, TEXT("%d - Blend (/GB) or Pentium Pro, Pentium II, Pentium III (/G6)"), _M_IX86);
else if (500 == _M_IX86)
swprintf_s(buffer, MAX_PATH, TEXT("%d - Pentium (/G5)"), _M_IX86);
else if (300 == _M_IX86)
swprintf_s(buffer, MAX_PATH, TEXT("%d - 80386 (/G3)"), _M_IX86);
else if (400 == _M_IX86)
swprintf_s(buffer, MAX_PATH, TEXT("%d - 80486 (/G4)"), _M_IX86);
else
swprintf_s(buffer, MAX_PATH, TEXT("%d - Unknown"), _M_IX86);
#else
swprintf_s(buffer, MAX_PATH, TEXT("Undefined"));
#endif
m_strOutput += buffer;
// _M_IA64 - Defined for Itanium Processor Family 64-bit processors.
m_strOutput += "\r\n";
m_strOutput += "Itanium Processor Family 64-bit [_M_IA64]: ";
#ifdef _M_IA64
swprintf_s(buffer, MAX_PATH, TEXT("%s (%d)"), TEXT("YES"), _M_IA64);
#else
swprintf_s(buffer, MAX_PATH, TEXT("NO"));
#endif
m_strOutput += buffer;
// _M_IX86_FP - Expands to a value indicating which /arch compiler option was used:
// 0 if /arch was not used.
// 1 if /arch:SSE was used.
// 2 if /arch:SSE2 was used.
m_strOutput += "\r\n";
m_strOutput += "Minimum CPU Architecture [_M_IX86_FP]: ";
#ifdef _M_IX86_FP
if (0 == _M_IX86_FP)
swprintf_s(buffer, MAX_PATH, TEXT("%d - %s"), _M_IX86_FP, TEXT("NO Streaming SIMD Extensions"));
else if (1 == _M_IX86_FP)
swprintf_s(buffer, MAX_PATH, TEXT("%d - %s"), _M_IX86_FP, TEXT("Streaming SIMD Extensions (/arch:SSE)"));
else if (2 == _M_IX86_FP)
swprintf_s(buffer, MAX_PATH, TEXT("%d - %s"), _M_IX86_FP, TEXT("Streaming SIMD Extensions 2 (/arch:SSE2)"));
else
swprintf_s(buffer, MAX_PATH, TEXT("%d - %s"), _M_IX86_FP, TEXT("UNKNOWN"));
#else
swprintf_s(buffer, MAX_PATH, TEXT("UNDEFINED"));
#endif
m_strOutput += buffer;
// Defined for Power Macintosh platforms (no longer supported).
m_strOutput += "\r\n";
m_strOutput += "Power Macintosh Platform [_M_MPPC]: ";
#ifdef _M_MPPC
swprintf_s(buffer, MAX_PATH, TEXT("%s (%d)"), TEXT("YES"), _M_MPPC);
#else
swprintf_s(buffer, MAX_PATH, TEXT("%s"), TEXT("NO"));
#endif
m_strOutput += buffer;
// Defined for MIPS platforms (no longer supported).
m_strOutput += "\r\n";
m_strOutput += "MIPS Platform (_M_MRX000): ";
#ifdef _M_MRX000
swprintf_s(buffer, MAX_PATH, TEXT("%s (%d)"), TEXT("YES"), _M_MRX000);
#else
swprintf_s(buffer, MAX_PATH, TEXT("%s"), TEXT("NO"));
#endif
m_strOutput += buffer;
// Defined for PowerPC platforms (no longer supported).
m_strOutput += "\r\n";
m_strOutput += "PowerPC Platform [_M_PPC]: ";
#ifdef _M_PPC
swprintf_s(buffer, MAX_PATH, TEXT("%s (%d)"), TEXT("YES"), _M_PPC);
#else
swprintf_s(buffer, MAX_PATH, TEXT("%s"), TEXT("NO"));
#endif
m_strOutput += buffer;
// Defined for x64 processors.
m_strOutput += "\r\n";
m_strOutput += "x64 Platform [_M_X64]: ";
#ifdef _M_X64
swprintf_s(buffer, MAX_PATH, TEXT("%s (%d)"), TEXT("YES"), _M_X64);
#else
swprintf_s(buffer, MAX_PATH, TEXT("%s"), TEXT("NO"));
#endif
m_strOutput += buffer;
// _MANAGED = Defined to be 1 when /clr is specified.
m_strOutput += "\r\n";
m_strOutput += "Managed Code [_MANAGED]: ";
#ifdef _MANAGED
swprintf_s(buffer, MAX_PATH, TEXT("%s (%d)"), TEXT("YES"), _MANAGED);
#else
swprintf_s(buffer, MAX_PATH, TEXT("%s"), TEXT("NO"));
#endif
m_strOutput += buffer;
// _MFC_VER - Defines the MFC version. For example, 0x0700 represents MFC version 7.
m_strOutput += "\r\n";
m_strOutput += "MFC Version [_MFC_VER]: ";
#ifdef _MFC_VER
swprintf_s(buffer, MAX_PATH, TEXT("0x%0.4X"), _MFC_VER);
#else
swprintf_s(buffer, MAX_PATH, TEXT("%s"), TEXT("UNDEFINED"));
#endif
m_strOutput += buffer;
// _MSC_EXTENSIONS - Defined when compiling with the /Ze compiler option (the default).
// Its value, when defined, is 1.
m_strOutput += "\r\n";
m_strOutput += "Microsoft Language Extensions [_MSC_EXTENSIONS]: ";
#ifdef _MSC_EXTENSIONS
swprintf_s(buffer, MAX_PATH, TEXT("%s (%d)"), TEXT("ENABLED"), _MSC_EXTENSIONS);
#else
swprintf_s(buffer, MAX_PATH, TEXT("%s"), TEXT("DISABLED"));
#endif
m_strOutput += buffer;
// _MSC_VER - Reports the major and minor versions of the compiler.
// For example, 1310 for Microsoft Visual C++ .NET 2003.
// 1310 represents version 13 and a 1.0 point release.
// The current compiler version is 1400.
m_strOutput += "\r\n";
m_strOutput += "Microsoft Compiler Version (_MSC_VER): ";
#ifdef _MSC_VER
swprintf_s(buffer, MAX_PATH, TEXT("%d"), _MSC_VER);
#else
swprintf_s(buffer, MAX_PATH, TEXT("%s"), TEXT("UNDEFINED"));
#endif
m_strOutput += buffer;
// __MSVC_RUNTIME_CHECKS - Defined when one of the /RTC compiler options is specified.
m_strOutput += "\r\n";
m_strOutput += "Run-Time Error Checks (__MSVC_RUNTIME_CHECKS): ";
#ifdef __MSVC_RUNTIME_CHECKS
swprintf_s(buffer, MAX_PATH, TEXT("%s (%d)"), TEXT("ENABLED"), __MSVC_RUNTIME_CHECKS);
#else
swprintf_s(buffer, MAX_PATH, TEXT("%s"), TEXT("DISABLED"));
#endif
m_strOutput += buffer;
// Defined when /MD or /MDd (Multithreaded DLL) or /MT or /MTd (Multithreaded) is specified.
m_strOutput += "\r\n";
m_strOutput += "Multithreaded (_MT): ";
#ifdef _MT
swprintf_s(buffer, MAX_PATH, TEXT("%s (%d)"), TEXT("YES"), _MT);
#else
swprintf_s(buffer, MAX_PATH, TEXT("%s"), TEXT("NO"));
#endif
m_strOutput += buffer;
// _NATIVE_WCHAR_T_DEFINED - Defined when /Zc:wchar_t is used.
m_strOutput += "\r\n";
m_strOutput += "wchar_t Is Native Type (_NATIVE_WCHAR_T_DEFINED): ";
#ifdef _NATIVE_WCHAR_T_DEFINED
swprintf_s(buffer, MAX_PATH, TEXT("%s (%d)"), TEXT("YES"), _NATIVE_WCHAR_T_DEFINED);
#else
swprintf_s(buffer, MAX_PATH, TEXT("%s"), TEXT("NO"));
#endif
m_strOutput += buffer;
// _OPENMP - Defined when compiling with /openmp, returns an integer representing the date of
// the OpenMP specification implemented by Visual C++.
// _OPENMP_dir.cpp
// compile with: /openmp
// #include <stdio.h>
// int main() { printf("%d\n", _OPENMP); }sdOutput200203
m_strOutput += "\r\n";
m_strOutput += "OpenMP Specification Date (_OPENMP): ";
#ifdef _OPENMP
swprintf_s(buffer, MAX_PATH, TEXT("%d"), _OPENMP);
#else
swprintf_s(buffer, MAX_PATH, TEXT("%s"), TEXT("UNDEFINED"));
#endif
m_strOutput += buffer;
// _VC_NODEFAULTLIB - Defined when /Zl is used; see /Zl (Omit Default Library Name) for more information.
m_strOutput += "\r\n";
m_strOutput += "Omit Default Library Name (_VC_NODEFAULTLIB): ";
#ifdef _VC_NODEFAULTLIB
swprintf_s(buffer, MAX_PATH, TEXT("%s (%d)"), TEXT("YES"), _VC_NODEFAULTLIB);
#else
swprintf_s(buffer, MAX_PATH, TEXT("%s"), TEXT("NO"));
#endif
m_strOutput += buffer;
// _WCHAR_T_DEFINED - Defined when /Zc:wchar_t is used or if wchar_t is defined in a system header
// file included in your project.
m_strOutput += "\r\n";
m_strOutput += "wchar_t Is Native Type (_WCHAR_T_DEFINED): ";
#ifdef _WCHAR_T_DEFINED
swprintf_s(buffer, MAX_PATH, TEXT("%s (%d)"), TEXT("YES"), _WCHAR_T_DEFINED);
#else
swprintf_s(buffer, MAX_PATH, TEXT("%s"), TEXT("NO"));
#endif
m_strOutput += buffer;
// _WIN32 - Defined for applications for Win32 and Win64. Always defined.
m_strOutput += "\r\n";
m_strOutput += "Windows 32-bit (_WIN32): ";
#ifdef _WIN32
swprintf_s(buffer, MAX_PATH, TEXT("%s (%d)"), TEXT("YES"), _WIN32);
#else
swprintf_s(buffer, MAX_PATH, TEXT("%s"), TEXT("NO"));
#endif
m_strOutput += buffer;
// Defined for applications for Win64.
m_strOutput += "\r\n";
m_strOutput += "Windows 64-bit (_WIN64): ";
#ifdef _WIN64
swprintf_s(buffer, MAX_PATH, TEXT("%s (%d)"), TEXT("YES"), _WIN64);
#else
swprintf_s(buffer, MAX_PATH, TEXT("%s"), TEXT("NO"));
#endif
m_strOutput += buffer;
// Defined when specifying /Wp64.
m_strOutput += "\r\n";
m_strOutput += "Detect 64-Bit Portability Issues (_Wp64): ";
#ifdef _Wp64
swprintf_s(buffer, MAX_PATH, TEXT("%s (%d)"), TEXT("YES"), _Wp64);
#else
swprintf_s(buffer, MAX_PATH, TEXT("%s"), TEXT("NO"));
#endif
m_strOutput += buffer;
return false;
}
When the function finishes m_strOutput contains a string looking something like this:
-- Microsoft-Specific Predefined Macros -- ATL Version: 0x0800 Default char Type Is unsigned [_CHAR_UNSIGNED]: NO Common Language Runtime Version [__CLR_VER]: UNDEFINED __cplusplus_cli: NO C++ Program [__cplusplus]: YES (199711) C++ Standard Library Header Version [_CPPLIB_VER]: UNDEFINED Enable Run-Time Type Information [_CPPRTTI]: YES (1) Enable Exception Handling [_CPPUNWIND]: YES (1) Debug Mode [_DEBUG]: YES (1) Multithread DLL [_DLL]: NO Function name (decorated) [__FUNCDNAME__]: ?UseMicrosoftSpecificPredefinedMacros@CPreprocessingDlg@@AAE_NXZ Function signature [__FUNCSIG__]: bool __thiscall CPreprocessingDlg::UseMicrosoftSpecificPredefinedMacros(void) Function name [__FUNCTION__]: CPreprocessingDlg::UseMicrosoftSpecificPredefinedMacros Integral type maximum size (in bits) [_INTEGRAL_MAX_BITS]: 64 DEC ALPHA Platform [_M_ALPHA]: NO Common Language Runtime Compilation [_M_CEE]: NO Common Language Runtime Pure Compilation [_M_CEE_PURE]: NO Common Language Runtime Safe Compilation [_M_CEE_SAFE]: NO Minimum CPU Architecture [_M_IX86]: 600 - Blend (/GB) or Pentium Pro, Pentium II, Pentium III (/G6) Itanium Processor Family 64-bit [_M_IA64]: NO Minimum CPU Architecture [_M_IX86_FP]: 0 - NO Streaming SIMD Extensions Power Macintosh Platform [_M_MPPC]: NO MIPS Platform (_M_MRX000): NO PowerPC Platform [_M_PPC]: NO x64 Platform [_M_X64]: NO Managed Code [_MANAGED]: NO MFC Version [_MFC_VER]: 0x0800 Microsoft Language Extensions [_MSC_EXTENSIONS]: ENABLED (1) Microsoft Compiler Version (_MSC_VER): 1400 Run-Time Error Checks (__MSVC_RUNTIME_CHECKS): ENABLED (1) Multithreaded (_MT): YES (1) wchar_t Is Native Type (_NATIVE_WCHAR_T_DEFINED): YES (1) OpenMP Specification Date (_OPENMP): UNDEFINED Omit Default Library Name (_VC_NODEFAULTLIB): NO wchar_t Is Native Type (_WCHAR_T_DEFINED): YES (1) Windows 32-bit (_WIN32): YES (1) Windows 64-bit (_WIN64): NO Detect 64-Bit Portability Issues (_Wp64): YES (1)
本文介绍了一个示例函数,该函数使用了ANSI兼容的预定义预处理器宏来展示如何利用微软特定的预定义宏。这些宏可以提供有关编译器特性、平台和编译选项的信息。
1004

被折叠的 条评论
为什么被折叠?



