In general, all lines in the source program are compiled. However, sometimes you want to compile a part of the content only when certain conditions are met, that is, specify the compilation conditions for a part of the content, which is "conditional compilation". Sometimes, you want to compile a group of statements when a certain condition is met, and compile another group of statements when the condition is not met.
#ifdef identifier
Program segment 1
#else
program segment 2
#endif
#ifdef
program segment 1
#denif
#ifdef WINDOWS
#define MYTYPE long
#else
#define MYTYPE float
#endif
#define WINDOWS at the beginning of the program
#define MYTYPE long
#define WINDOWS 0
#ifdef DEBUG
print ("device_open(%p)n", file);
#endif
#define DEBUG
#ifndef identifier
Program segment 1
#else
program segment 2
#endif
#if expression
Program segment 1
#else
program segment 2
#endif
#define LETTER 1
main()
{
char str[20]="C Language",c;
int i=0;
while((c=str[i])!=''){
i++;
#if LETTER
if(c>='a'&&c<='z') c=c-32;
#else
if(c>='A'&&c<='Z') c=c+32;
#endif
printf("%c",c);
}
}
#define LETTER 0
#ENDIF
#define __CONFIG_H
There is only an identifier after #define, but no replaced number. Can anyone explain what this means?
You are talking about the file in .h. There should be a #endif at the end, which is written to avoid the .h file from being redefined. For example, AC includes BH and CH, and BH includes CH. When AC is compiled, CH will be compiled repeatedly. When
#ifndef __CONFIG_H is written before CH,
#ifndef __CONFIG_H
#ifndef __CONFIG_H will not pass because it has been defined before. It avoids redefinition.
To summarize:
Use #ifndef to prevent duplicate definitions. It is just a macro definition, which is mostly used in exclusive definitions in C language. The most common usage is to completely encapsulate the entire public header file to avoid nested references and duplicate definitions. The general usage is as follows:
#ifndef __CONFIG_H
#define __CONFIG_H
header file body
#define __CONFIG_H
Previous article:What does code mean in C language of microcontroller?
Next article:Serial communication working mode 1 baud rate calculation
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- How haptic technology can enhance driving safety
- Let’s talk about the “Three Musketeers” of radar in autonomous driving
- Why software-defined vehicles transform cars from tools into living spaces
- How Lucid is overtaking Tesla with smaller motors
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Vietnam's chip packaging and testing business is growing, and supply-side fragmentation is splitting the market
- Vietnam's chip packaging and testing business is growing, and supply-side fragmentation is splitting the market
- Three steps to govern hybrid multicloud environments
- Three steps to govern hybrid multicloud environments
- Fluke Award-winning Live Broadcast | Basics of Data Loggers, Their Applications and Calibration
- Regarding power supply, let me share a particularly inspiring story...
- Embedded Systems Basics: Understanding Embedded Systems
- [FM33LG0 Series Development Board Review] 06.CAN
- [Revenge RVB2601 creative application development] About my development board welcomes the audio change
- EEWORLD University Hall----Live playback: The latest low-power 5GHz dual-band Wi-Fi MCU fully meets high security standards
- 【TI recommended course】#LED function introduction and LED driver design considerations#
- Live broadcast at 10 am today [A new generation of products based on the optimized design of Melexis second-generation position sensors]
- If a multi-channel BUCK IC drives different loads, can the GND output to the loads be shared?
- 2021 Python Developer Survey Results