Summary of work-using preprocessing commands and macros

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.