关于Visual Studio 6.0中preprocessor的使用心得

来源:互联网 发布:oppor7怎么隐藏软件 编辑:程序博客网 时间:2024/05/22 17:01

1.       在项目上点击右键->setting->C/C++->Preprocessor definitions

2.       Preprocessor definitions中可以自定义预编译头,我在里面自定义了_JIMMY_PROMIS两个预编译头

3.       编写测试代码,代码如下:

#include <stdio.h>

#include <stdlib.h>

 

int main()

{

 

#ifdef _JIMMY

       printf("The preprocessor is _JIMMY!/n");

 

//#elif _PROMIS

//     printf("The preprocessor is PROMIS!/n");

 

#else

       printf("The preprocessor is others!/n");

 

#endif

 

#ifdef _PROMIS

       printf("The preprocessor is PROMIS!/n");

#else

       printf("The preprocessor is others!/n");

#endif

 

       return 0;

}

程序输出如下:

The preprocessor is _JIMMY!

The preprocessor is PROMIS!

从此我们可以得出一个结论:(1)每次执行#ifdef的时候都会去Preprocessor definitions处查找有没有预编译头,一个预编译头只能用一次#ifdef

2)如果在一个#ifdef中用#else包含另外一个预编译头,也不会执行;每个预编译头只能包含在一个#ifdef中!

3)预编译头区分大小写