| 網站首頁 | 關于我們 | 開發(fā)優(yōu)勢 | 產品展示 |
| 合作企業(yè) | 新聞動態(tài) | 聯(lián)系我們 | 電話聯(lián)系 |
文章作者:濟南軟件開發(fā) 時間:2016年11月08日
C語言中的預編譯包含三種:1.宏定義2.文件包含3.條件編譯,條件編譯指的是滿足一定條件下才進行編譯,它有幾種形式:
(1)#ifdef標識符
//程序
#else
//程序
#endif
它的意義為如果定義了標識符,則執(zhí)行程序段1,否則執(zhí)行程序段2
或者用以下的形式
# ifdef 標識符
//程序
#endif
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# include <stdio.h>
# include <stdlib.h>
int main()
{
#ifdef DEBUG
printf("debug is running\n");
#else
printf("debug is not running\n");
#endif
system("pause");
return 0;
}
</stdlib.h></stdio.h>
(2)
#ifndef 標識符
//程序1
#else
//程序2
#endif
它的含義是如果標識符沒有被定義,則執(zhí)行程序段1,否則執(zhí)行程序段2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# include <stdio.h>
# include <stdlib.h>
int main()
{
#ifndef DEBUG
printf("debug is not running\n");
#else
printf("debug is running\n");
#endif
system("pause");
return 0;
}
</stdlib.h></stdio.h>
(3)#if表達式
//程序1
#else
//程序2
#endif
它的意義為表達式的值為真時,就編譯程序段1,表達式的值為假時,就編譯程序段2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# include <stdio.h>
# include <stdlib.h>
# define HEX 1
int main()
{
int i=10;
#if HEX==1
printf("%x\n",i);
#else
printf("%d\n",i);
#endif
system("pause");
return 0;
}</stdlib.h></stdio.h>
想要了解更多詳情歡迎來電咨詢18678812288
登陸網址:m.h6244.cn。
聯(lián)系人:王經理。