当前位置:网站首页>#if,#ifdef和#ifndef三者之间的区别
#if,#ifdef和#ifndef三者之间的区别
2022-07-19 18:03:00 【Kevin张俊杰】
条件编译
预处理程序提供了条件编译的功能。 可以按不同的条件去编译不同的程序部分,因而产生不同的目标代码文件。 这对于程序的移植和调试是很有用的。
条件编译的三种形式
第一种形式:
#ifdef 标识符 程序段1 #else 程序段2 #endif
它的功能是,如果标识符已被
#define
命令定义过则对程序段1进行编译;否则对程序段2进行编译。第二种形式:
#ifndef 标识符 程序段1 #else 程序段2 #endif
与第一种形式的区别是将
ifdef
改为ifndef
。它的功能是,如果标识符未被#define
命令定义过则对程序段1进行编译, 否则对程序段2进行编译。这与第一种形式的功能正相反。第三种形式:
#if 常量表达式 程序段1 #else 程序段2 #endif
它的功能是,如常量表达式的值为真(非0),则对程序段1 进行编译,否则对程序段2进行编译。因此可以使程序在不同条件下,完成不同的功能。
附注—》#elif 用法
#elif
指令可以被认为是#else if
#elif
指令必须由#endif
指令关闭
#include <stdio.h>
#define YEARS_OLD 12
int main()
{
#if YEARS_OLD <= 10
printf("TechOnTheNet is a great resource.\n");
#elif YEARS_OLD > 10
printf("TechOnTheNet is over %d years old.\n", YEARS_OLD);
#endif
return 0;
}
边栏推荐
- SIGGRAPH 2022--岩鸽彩虹色羽毛渲染阅读笔记:Rendering Iridescent Rock Dove Neck Feathers
- Arrow function in ES6
- ES6函数参数默认值,以及rest参数
- 载他克莫司的HSA蛋白纳米粒/DCT-BSA多西紫杉醇白蛋白纳米粒/血清白蛋白-透明质酸纳米颗粒的制备
- R语言获取data.table数据中指定数据列的第N个最大值所在的数据行
- Preparation of GL hsanps glycyrrhizic acid coupled human serum albumin loaded resveratrol / Rhein phospholipid complex serum protein nanoparticles
- [paper sharing] security and protection status of decentralized Finance (DFI)
- Elk cluster architecture optimization
- Preparation of PDA RBCs NPs polydopamine modified erythrocyte nanoparticles / hyaluronic acid coated brucine bovine serum protein nanoparticles
- csdn涨薪技术之UI⾃动化⼯具: UiAutomator2
猜你喜欢
【软件测试】—— 水杯测试用例
Promise实现
Basset: apprendre le Code réglementaire du génome accessible avec un réseau neuronal profond et cohérent
面试官必问的 3 道 MQ 面试题,还有谁不会??
Crazy God redis notes 03
Res bsanp resveratrol albumin nanoparticles / albumin nanoparticles carrier encapsulated with taxanes
百度、阿里、腾讯,谁最先倒下?
50个名额限量开放|带着OceanBase年度发布会的消息走来了!
使用 Abp.Zero 搭建第三方登录模块(四):微信小程序开发
Who else can't answer the three MQ interview questions that an interviewer must ask??
随机推荐
[IVX from introduction to mastery · opening] initial IVX -- zero code visual programming language
ES6函数参数默认值,以及rest参数
ffmpeg笔记(一)音视频基础
网易游戏 Flink SQL 平台化实践
MySQL common statement knowledge points
Preparation of tacrolimus loaded HSA protein nanoparticles / dct-bsa docetaxel albumin nanoparticles / serum albumin hyaluronic acid nanoparticles
50个名额限量开放|带着OceanBase年度发布会的消息走来了!
赛迪发布《湖仓一体技术研究报告》,巨杉数据库入选国内企业典型代表
ELK集群架构优化
C100:尺寸最小的HEVC视觉物联网 MCU
小米 12S Utra 莱卡水印生成在线工具
PyGame official document [translation] - pygame freetype
面试官必问的 3 道 MQ 面试题,还有谁不会??
【云驻共创】与最年轻的云服务HCIE一起设计华为云存储架构(下篇)
R语言获取data.table数据中指定数据列的第N个最大值所在的数据行
发力5G笔记本市场,闻泰科技加入“鸿鹄计划”
安世半导体管理层拜会闻泰科技和格力电器
Prepare for the interview and stick to the second sentence of "100 days and 100 questions · basic chapter" - basic data types and operators!
[paper sharing] security and protection status of decentralized Finance (DFI)
Pygame 官方文档 【翻译】- pygame.freetype