Software in the work needs to start different video capture hardware in different application scenarios. There are three methods to start:
1. Pre-processing commands and macros are used to process code of different hardware;
2. Identify by hard-coded hardware identification code;
3. Use the UI for user selection;
Let's take a look at the first one.
Understanding # define
Syntax:
# Define ID replacement list
# Define identifier [(identifier, select..., identifier)] replacement list
There is actually another form
# Define identifier
In this form, the identifier is not defined as any value. In other words, a null value is defined, and you cannot use it to judge any value.
Therefore, this identifier can only be compiled and controlled by determining whether it is defined.
If vs2005 is used as the IDE, # define identifier is equivalent to the following settings in vs2005:
This defined Application Scenario:
1. Prevent the same file from being repeatedly contained multiple times;
2. Used for Conditional compilation. (This is a type of C pre-compiled command. The C language pre-compiled Commands include macro definition, file inclusion, and Conditional compilation ).
Example:
1. Prevent the same file from being repeatedly contained multiple times;
# Ifndef _ SOMEFILE_H __
# Define _ SOMEFILE_H __
... // Some declaration statements
# Endif
2. It is used for Conditional compilation, which is the usage in my work software.
# Ifdef COND
One choice code
# Else
Other Choice code
# Endif