In the case of C language Conditional compilation, I am guilty. I do not know what it means. The macro definition in the C Language header file,

Source: Internet
Author: User

In the case of C language Conditional compilation, I am guilty. I do not know what it means. The macro definition in the C Language header file,

Preface

When you see the Conditional compilation in the header file, you are guilty. I don't know what it means. However, your teacher says, "you have to write it like that." You do it, but you know it, but you don't know why. My understanding is as follows ~~~ This is an ugly individual. You can read it for new users.

Code segment

Rising posture

Analysis:

Rows 1st, 2, and 14th: avoid repeated definitions. That is, the first part:

When this file is contained for the first time, the macro DSP_ADC_BSP_H _ is not defined, and the Preprocessor is allowed to retain multiple lines between # ifndef and # endif.

If the file is contained again, the Preprocessor deletes the content between # ifndef and # endif. This means that if two. c files contain the. h file at the same time, it will be defined only once.

3rd ~ Row 12: external functions and variables can be used in other modules only once in the. h file.

First, describe extern:

Extern int I;

The declared information provided by the compiler is that I is an int variable, but the compiler does not allocate storage units for I. The above Declaration is not a definition of variables, but a prompt that the compiler needs to access the variables defined elsewhere.

Variables can be declared multiple times in the program, but can only be defined once.

The. c file of the corresponding module contains the following sentence:

# Define _ DSP_ADC_BSP_C _ // defines _ DSP_ADC_BSP_C _

When this module. c file is used, the ADCBSPEXT is replaced with a blank one.

The function declaration is:

When these functions are used for other. c files, ADCBSPEXT is replaced with extern for use.

Well, today's sharing is here, and the content is very small. We should all know the basics. Ugly here



  • This article has been included in the following columns:

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.