VC++预定义宏(Predefined Macrod)

2024-03-28 20:32

本文主要是介绍VC++预定义宏(Predefined Macrod),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

为了方便自己查询,从MSDN转载一份放在这里。

From:msdn.microsoft.com/en-us/library/b0084kay(VS.80).aspx

C/C++ Preprocessor Reference

Predefined Macros

Names the predefined ANSI C and Microsoft C++ implementation macros.

The compiler recognizes predefined ANSI C macros and the Microsoft C++ implementation provides several more. These macros take no arguments and cannot be redefined. Some of the predefined macros listed below are defined with multiple values. See the following tables for more information.

ANSI-Compliant Predefined Macros
MacroDescription

__DATE__

The compilation date of the current source file. The date is a string literal of the form Mmm dd yyyy. The month name Mmm is the same as for dates generated by the library function asctime declared in TIME.H.

__FILE__

The name of the current source file. __FILE__ expands to a string surrounded by double quotation marks. To ensure that the full path to the file is displayed, use /FC (Full Path of Source Code File in Diagnostics).

You can create your own wide string version of __FILE__ as follows:

#include <stdio.h>
#define WIDEN2(x) L ## x
#define WIDEN(x) WIDEN2(x)
#define __WFILE__ WIDEN(__FILE__)
wchar_t *pwsz = __WFILE__;
int main() {}

__LINE__

The line number in the current source file. The line number is a decimal integer constant. It can be altered with a #line directive.

__STDC__

Indicates full conformance with the ANSI C standard. Defined as the integer constant 1 only if the /Za compiler option is given and you are not compiling C++ code; otherwise is undefined.

__TIME__

The most recent compilation time of the current source file. The time is a string literal of the form hh:mm:ss.

__TIMESTAMP__

The date and time of the last modification of the current source file, expressed as a string literal in the form Ddd Mmm Date hh:mm:ss yyyy, where Ddd is the abbreviated day of the week and Date is an integer from 1 to 31.

Microsoft-Specific Predefined Macros
MacroDescription

_ATL_VER

Defines the ATL version.

_CHAR_UNSIGNED

Default char type is unsigned. Defined when /J is specified.

__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.

// clr_ver.cpp
// compile with: /clr
using namespace System;
int main() {
Console::WriteLine(__CLR_VER);
}

__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.

// cplusplus_cli.cpp
// compile with: /clr
#include "stdio.h"
int main() {
#ifdef __cplusplus_cli
printf("%d\n", __cplusplus_cli);
#else
printf("not defined\n");
#endif
}

__COUNTER__

Expands to an integer starting with 0 and incrementing by 1 every time it is used in a compiland. __COUNTER__ remembers its state when using precompiled headers. If the last __COUNTER__ value was 4 after building a precompiled header (PCH), it will start with 5 on each PCH use.

__COUNTER__ lets you generate unique variable names. You can use token pasting with a prefix to make a unique name. For example:

// pre_mac_counter.cpp
#include <stdio.h>
#define FUNC2(x,y) x##y
#define FUNC1(x,y) FUNC2(x,y)
#define FUNC(x) FUNC1(x,__COUNTER__)
int FUNC(my_unique_prefix);
int FUNC(my_unique_prefix);
int main() {
my_unique_prefix0 = 0;
printf_s("\n%d",my_unique_prefix0);
my_unique_prefix0++;
printf_s("\n%d",my_unique_prefix0);
}

__cplusplus

Defined for C++ programs only.

_CPPLIB_VER

Defined if you include any of the C++ Standard Library headers; reports which version of the Dinkumware header files are present.

_CPPRTTI

Defined for code compiled with /GR (Enable Run-Time Type Information).

_CPPUNWIND

Defined for code compiled with /GX (Enable Exception Handling).

_DEBUG

Defined when compiling with /LDd, /MDd, and /MTd.

_DLL

Defined when /MD or /MDd (Multithread DLL) is specified.

__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.

__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.

On a 64-bit operating system, the calling convention is __cdecl by default.

__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.

_INTEGRAL_MAX_BITS

Reports the maximum size (in bits) for an integral type.

// integral_max_bits.cpp
#include <stdio.h>
int main() {
printf("%d\n", _INTEGRAL_MAX_BITS);
}

_M_ALPHA

Defined for DEC ALPHA platforms (no longer supported).

_M_CEE

Defined for a compilation that uses any form of /clr (/clr:oldSyntax, /clr:safe, for example).

_M_CEE_PURE

Defined for a compilation that uses /clr:pure.

_M_CEE_SAFE

Defined for a compilation that uses /clr:safe.

_M_IX86

Defined for x86 processors. See Values for _M_IX86 for more details.

_M_IA64

Defined for Itanium Processor Family 64-bit processors.

_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.

  • See /arch (Minimum CPU Architecture) for more information.

_M_MPPC

Defined for Power Macintosh platforms (no longer supported).

_M_MRX000

Defined for MIPS platforms (no longer supported).

_M_PPC

Defined for PowerPC platforms (no longer supported).

_M_X64

Defined for x64 processors.

_MANAGED

Defined to be 1 when /clr is specified.

_MFC_VER

Defines the MFC version. For example, 0x0700 represents MFC version 7.

_MSC_EXTENSIONS

This macro is defined when compiling with the /Ze compiler option (the default). Its value, when defined, is 1.

_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 Visual C++ 2005 compiler version is 1400.

Type cl /? at the command line to see the major and minor versions of your compiler along with the build number.

__MSVC_RUNTIME_CHECKS

Defined when one of the /RTC compiler options is specified.

_MT

Defined when /MD or /MDd (Multithreaded DLL) or /MT or /MTd (Multithreaded) is specified.

_NATIVE_WCHAR_T_DEFINED

Defined when /Zc:wchar_t is used.

_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);
}

_VC_NODEFAULTLIB

Defined when /Zl is used; see /Zl (Omit Default Library Name) for more information.

_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.

_WIN32

Defined for applications for Win32 and Win64. Always defined.

_WIN64

Defined for applications for Win64.

_Wp64

Defined when specifying /Wp64.

As shown in following table, the compiler generates a value for the preprocessor identifiers that reflect the processor option specified.

Values for _M_IX86
Option in Development EnvironmentCommand-Line OptionResulting Value

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

这篇关于VC++预定义宏(Predefined Macrod)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/856624

相关文章

使用C++实现链表元素的反转

《使用C++实现链表元素的反转》反转链表是链表操作中一个经典的问题,也是面试中常见的考题,本文将从思路到实现一步步地讲解如何实现链表的反转,帮助初学者理解这一操作,我们将使用C++代码演示具体实现,同... 目录问题定义思路分析代码实现带头节点的链表代码讲解其他实现方式时间和空间复杂度分析总结问题定义给定

C++初始化数组的几种常见方法(简单易懂)

《C++初始化数组的几种常见方法(简单易懂)》本文介绍了C++中数组的初始化方法,包括一维数组和二维数组的初始化,以及用new动态初始化数组,在C++11及以上版本中,还提供了使用std::array... 目录1、初始化一维数组1.1、使用列表初始化(推荐方式)1.2、初始化部分列表1.3、使用std::

C++ Primer 多维数组的使用

《C++Primer多维数组的使用》本文主要介绍了多维数组在C++语言中的定义、初始化、下标引用以及使用范围for语句处理多维数组的方法,具有一定的参考价值,感兴趣的可以了解一下... 目录多维数组多维数组的初始化多维数组的下标引用使用范围for语句处理多维数组指针和多维数组多维数组严格来说,C++语言没

c++中std::placeholders的使用方法

《c++中std::placeholders的使用方法》std::placeholders是C++标准库中的一个工具,用于在函数对象绑定时创建占位符,本文就来详细的介绍一下,具有一定的参考价值,感兴... 目录1. 基本概念2. 使用场景3. 示例示例 1:部分参数绑定示例 2:参数重排序4. 注意事项5.

使用C++将处理后的信号保存为PNG和TIFF格式

《使用C++将处理后的信号保存为PNG和TIFF格式》在信号处理领域,我们常常需要将处理结果以图像的形式保存下来,方便后续分析和展示,C++提供了多种库来处理图像数据,本文将介绍如何使用stb_ima... 目录1. PNG格式保存使用stb_imagephp_write库1.1 安装和包含库1.2 代码解

C++实现封装的顺序表的操作与实践

《C++实现封装的顺序表的操作与实践》在程序设计中,顺序表是一种常见的线性数据结构,通常用于存储具有固定顺序的元素,与链表不同,顺序表中的元素是连续存储的,因此访问速度较快,但插入和删除操作的效率可能... 目录一、顺序表的基本概念二、顺序表类的设计1. 顺序表类的成员变量2. 构造函数和析构函数三、顺序表

使用C++实现单链表的操作与实践

《使用C++实现单链表的操作与实践》在程序设计中,链表是一种常见的数据结构,特别是在动态数据管理、频繁插入和删除元素的场景中,链表相比于数组,具有更高的灵活性和高效性,尤其是在需要频繁修改数据结构的应... 目录一、单链表的基本概念二、单链表类的设计1. 节点的定义2. 链表的类定义三、单链表的操作实现四、

使用C/C++调用libcurl调试消息的方式

《使用C/C++调用libcurl调试消息的方式》在使用C/C++调用libcurl进行HTTP请求时,有时我们需要查看请求的/应答消息的内容(包括请求头和请求体)以方便调试,libcurl提供了多种... 目录1. libcurl 调试工具简介2. 输出请求消息使用 CURLOPT_VERBOSE使用 C

C++实现获取本机MAC地址与IP地址

《C++实现获取本机MAC地址与IP地址》这篇文章主要为大家详细介绍了C++实现获取本机MAC地址与IP地址的两种方式,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 实际工作中,项目上常常需要获取本机的IP地址和MAC地址,在此使用两种方案获取1.MFC中获取IP和MAC地址获取

C/C++通过IP获取局域网网卡MAC地址

《C/C++通过IP获取局域网网卡MAC地址》这篇文章主要为大家详细介绍了C++如何通过Win32API函数SendARP从IP地址获取局域网内网卡的MAC地址,感兴趣的小伙伴可以跟随小编一起学习一下... C/C++通过IP获取局域网网卡MAC地址通过win32 SendARP获取MAC地址代码#i