posts - 16,  comments - 34,  trackbacks - 0

一、 介绍预定义宏 "_MSC_VER"

        一.1 _MSC_VER是微软C/C++编译器——cl.exe编译代码时预定义的一个宏。

需要针对cl编写代码时, 可以使用该宏进行条件编译。

        一.2 _MSC_VER的值表示cl的版本。

需要针对cl特定版本编写代码时, 也可以使用该宏进行条件编译。
对应关系点链接查看。

        一.3 _MSC_VER的类型是"int"

该宏被扩展后,得到的是整数字面值
可以通过仅预处理, 查看宏扩展后的文本。见:《查看源文件预处理结果》。
同时下面的示例也能体现出这一点。




二、 测试预定义宏 _MSC_VER

示例:
/* _MSC_VER\_MSC_VER.cpp */
#include 
<stdio.h>
#include 
<stdlib.h>
#include 
<typeinfo>

#define TO_LITERAL(text) TO_LITERAL_(text)
#define TO_LITERAL_(text) #text

#ifndef _MSC_VER
#error sample for msvc compiler
#else
/* use msvc special extension: #pragma message,__declspec,__stdcall,etc. */

#pragma message(
"----------------------------------------\n")
#pragma message(
"----------------------------------------\n")
#pragma message(
"---------- hello msvc " TO_LITERAL(_MSC_VER) " -------------")
#pragma message(
"\n----------------------------------------\n")
#pragma message(
"----------------------------------------\n")

extern __declspec(dllimport) void __stdcall declare_but_dont_reference(void);
#endif

int main() {
    printf(
"hello msvc, version=%d\n",_MSC_VER);
    printf(
"typeof _MSC_VER=\"%s\"\n",typeid(_MSC_VER).name());
    system(
"pause"); /* msvc only on windows? */
    
return 0;
}





修改:

—— 2009/04/18

Evaluates to the major and minor number components of the compiler's version number. The major number is the first component of the period-delimited version number and the minor number is the second component.

For example, if the version number of the VC++ compiler is 15.00.20706.01, the _MSC_VER macro evaluates to 1500.


            ——http://msdn.microsoft.com/en-us/library/b0084kay.aspx




相关链接:

—— 示例下载
http://immature.googlecode.com/svn/trunk/iMmature/sample/predefined_macro/extension/_MSC_VER/
http://www.cppblog.com/Files/ownwaterloo/_MSC_VER.zip
该示例涉及到以下两篇文章的内容:

——《配置msvc命令行环境》
http://www.cppblog.com/ownwaterloo/archive/2009/04/15/environment_for_using_cl_from_command_line.html
——《配置msvc命令行环境(续)——编写msvc编译脚本》
http://www.cppblog.com/ownwaterloo/archive/2009/04/16/write_compile_script_for_msvc.html


——VC版本表
http://www.cppblog.com/ownwaterloo/archive/2009/04/15/environment_for_using_cl_from_command_line.html#VS_VC_CL_MSC_VER_TABLE
——《查看源文件预处理结果》
http://www.cppblog.com/ownwaterloo/archive/2009/04/16/get_result_of_preprocessing.html


——《预定义__GNUC__宏》
http://www.cppblog.com/ownwaterloo/archive/2009/04/16/predefined_macro___GNUC__.html



Creative Commons License
作品采用知识共享署名-非商业性使用-相同方式共享 2.5 中国大陆许可协议进行许可。

转载请注明 :
文章作者 - OwnWaterloo
发表时间 - 2009年04月15日
原文链接 - http://www.cppblog.com/ownwaterloo/archive/2009/04/15/predefined_macro__MSC_VER.html

posted on 2009-04-15 21:12 OwnWaterloo 阅读(7981) 评论(1)  编辑 收藏 引用

FeedBack:
# re: 预定义_MSC_VER宏[未登录]
2013-01-24 17:10 | lance
很好的文章,转载一下,谢谢。。。^_^  回复  更多评论
  

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2013年1月>
303112345
6789101112
13141516171819
20212223242526
272829303112
3456789

常用链接

留言簿(8)

随笔档案(16)

链接

搜索

  •  

积分与排名

  • 积分 - 194757
  • 排名 - 132

最新随笔

最新评论

阅读排行榜

评论排行榜