#define macro definition
#undef cancels the defined macro name
#include causes the compiler to embed another source file into the source file with #include
#if
#line changes the current line number and file name, which are predefined identifiers in the compiler.
The basic form of the command is as follows: #line number["filename"]
#error When compiling a program, as soon as #error is encountered, a compilation error message will be generated and compilation will stop.
#pragma
Conditional compilation
The conditional compilation function allows us to compile different parts of a program according to different conditions, thereby generating different target code files. This is very useful for program porting and debugging. There are three forms of conditional compilation, which are introduced below.
The first form:
#ifdef identifier
Segment 1
#else
Segment 2
#endif
Its function is to compile program segment 1 if the identifier has been defined by the #define command; otherwise, compile program segment 2. If there is no program segment 2 (it is empty), the #else in this format can be omitted, that is, it can be written as:
#ifdef identifier
program segment
#endif
The second form:
#ifndef identifier
program segment 1
#else
program segment 2
#endif
is different from the first form in that "ifdef" is changed to "ifndef". Its function is to compile program segment 1 if the identifier has not been defined by the #define command, otherwise, compile program segment 2. This is the opposite of the function of the first form.
The third form:
#if constant expression
Program segment 1
#else
program segment 2
#endif
Its function is to compile program segment 1 if the value of the constant expression is true (non-0), otherwise compile program segment 2. Therefore, the program can perform different functions under different conditions.
As for the #elif command, its meaning is the same as else if. It forms an if else-if ladder statement, which can make multiple compilation options.
Previous article:STM8s--Timer (time4)
Next article:extern and header files
- 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
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- Brief Analysis of Automotive Ethernet Test Content and Test Methods
- How haptic technology can enhance driving safety
- Is it better to first increase the voltage to 5V and then decrease it to 3.3V when using a 3.7V lithium battery? Or is it better to first decrease it to 3.3V and then increase it to 5V?
- Download the Pomona Connectors catalogue and win a Xiaomi Mosquito Repellent!
- Are smaller components better?
- Anyone have any ADS simulation tutorials to share?
- The Xiaomi IoT module wifi version only costs 9.99 yuan. What would you most like to use it for?
- EEWORLD University ---- EDDP Motor Control Demonstration Platform Usage Guide
- SILICON LABS PG22-DK2503A EFM32PG22 Development Kit Unboxing Review
- Parsing STM32 library functions.pdf
- The light-off operation of the Nuvoton MCU assembly is invalid
- PD power supply detection and requirements