当前位置:网站首页>The C programming language-2nd-- notes -- 4.11.3
The C programming language-2nd-- notes -- 4.11.3
2022-07-27 11:31:00 【YovaVan】
4.11.3 Conditions include
Conditional statements can be used to control the preprocessing itself , The value of this conditional statement is calculated during the execution of preprocessing . This method provides a means for selectively including different codes according to the calculated condition values in the compilation process .
#if Statement on the constant integer expression in it ( It cannot contain sizeof、 Type converter or enum Constant ) evaluation , If the value of the expression is not equal to 0, Then include the following lines , Until I met #endif、#elif or #else The statement so far ( Preprocessing statement #elif class else if). stay #if Expressions available in statements defined( name ), The value of this expression follows : When the name is defined , Its value is 1; otherwise , Its value is 0.
example , To guarantee hdr.h The content of is only included once , You can include the contents of this file in the following conditional statements :
#if !defined(HDR)
#define HDR
/*hdr.h Put the contents of here */
#endifFirst inclusion hdr.h When , Will define the name HDR; Then include this again .h when , The name is already defined , Jump directly to #endif It's about . A similar method can also be used to avoid repeatedly including the same file . If multiple header files can use this method consistently , Then each header file can include any header file it depends on , Users do not have to consider the various dependencies between and processing header files .
The following preprocessing code tests the system variables first SYSTEM, Then determine which version of header file to include according to the value of this variable ;
#if SYSTEM == SYSV
#define HDR "sysv.h"
#elif SYSTEM == BSD
#define HDR "bsd.h"
#elif SYSTEM == MSDOS
#define HDR "msdos.h"
#else
#define HDR "default.h"
#endif
#include HDRC Language specifically defines two preprocessing statements #ifdef And #ifndef, Used to test whether a name has been defined . It's about #if The first example of can be changed to :
#ifndef HDR
#define HDR
/*hdr.h File contents here */
#endif边栏推荐
- Vscode establishes automatic search of header files under non engineering directories
- What is the issuing price of NFT (Interpretation of NFT and establishment of NFT world outlook)
- Caused by:org.gradle.api.internal. plugins . PluginApplicationException: Failed to apply plugin
- 最长上升子序列模型 AcWing 272. 最长公共上升子序列
- Game theory acwing 893. Set Nim game
- 状态压缩DP AcWing 91. 最短Hamilton路径
- The C programming language (2nd) -- Notes -- 1.8
- 349 sum of intersection of two arrays and 01
- 博弈论 AcWing 893. 集合-Nim游戏
- Luogu p1896 non aggression
猜你喜欢

Longest ascending subsequence model acwing 482. Chorus formation

2022牛客多校 (3)J.Journey

Vscode establishes automatic search of header files under non engineering directories

Interval problem acwing 906. Interval grouping

Redis simple to use

深析C语言的灵魂 -- 指针

ACM warm-up Exercise 2 in 2022 summer vacation (summary)

An article reveals the NFT strategy of traditional game manufacturers such as Ubisoft

State compression DP acwing 91. shortest Hamilton path

WGet warning: unable to verify
随机推荐
什么是私域流量?
Tree DP acwing 285. dance without boss
ACM warm-up Exercise 1 in 2022 summer vacation (summary)
Gaussian elimination acwing 883. solving linear equations with Gaussian elimination
(4) Operator
8 find subsequences with a maximum length of K
"My" bug collection (Reprinted)
Error while unzipping file in win10: unable to create symbolic link. You may need to run WinRAR with administrator privileges. The client does not have the required privileges
(10) File contains
最长上升子序列模型 AcWing 272. 最长公共上升子序列
Quantitative industry knowledge summary
Game theory acwing 894. Split Nim game
Basic use of cmake
中国剩余定理 AcWing 204. 表达整数的奇怪方式
Memory search acwing 901. Skiing
C programming language (2nd Edition) -- Reading Notes -- 1.5.3
栈 AcWing 3302. 表达式求值
求组合数 AcWing 886. 求组合数 II
The C programming language (2nd) -- Notes -- 1.6
Redis simple to use