In the include statement containing the header file, what is the difference between double quotation marks and angle brackets?

Source: Internet
Author: User

# Incluce "" format:

Reference the header file of a non-standard library, and the compiler starts searching from the user's working directory. Double quotation marks indicate that the source file is located in the directory where the program source file is located. If the source file is not found, it is searched in the default directory of the system. It is usually used to include the header file compiled by the program author; angle brackets indicate that you can only search for the path in the default system directory or in the brackets. They are usually used to include the header files that are self-contained in the system.

Angle brackets: searches in the directory containing files (including directories are set by the user when setting the environment), rather than in the source file directory;

Double quotation marks: first, search in the current source file directory. If not found, search in the included directory.

Details: 

After the Preprocessor discovers the # include command, it will find the file name followed by it and include the content of this file into the current file. The text in the contained file will replace the # include command in the source code file, just as you type all the content in the contained file into this location in the source file.

# The include command can be used in two forms:

# Include <stdio. h> put the file name in angle brackets # include "mystuff. H" put the file name in double quotation marks

Brackets <and> indicate that the file is a project or standard header file. The search process checks the predefined directories. You can modify these directories by setting the search PATH environment variables or command line options.

If the file name is enclosed by a pair of quotation marks, it indicates that the file is the header file provided by the user.

The file will be searched for from the current file directory (or other Directories specified by the file name), and then find the file in the standard location.

Why include files?

Because these files contain the information required by the compiler. For example, stdio. H files generally contain EOF, null, getchar (), and putchar () definitions. Containing large header files does not necessarily increase the program size significantly. In many cases, the content in the header file is the information required by the compiler to generate the final code, rather than the specific statement added to the final code. The contained file can also contain the # include indicator. A header file may be contained in a source file multiple times due to nested inclusion, the condition indicator prevents repeated processing of such header files.

For example:

# Ifndef bookstore_h # define bookstore_h # endif

Condition Indicator # ifndef check whether bookstore_h has been defined before. Here, bookstore_h is a pre-compiler constant. Traditionally, pre-compiler constants are often written into uppercase letters, if bookstore_h is not defined before, the value of the Condition Indicator is true. Therefore, all statements from # ifndef to # endif are included for processing. On the contrary, if the value of the # ifndef indicator is false, the line between it and the # endif indicator will be ignored. To ensure that the header file is only processed once, the following # define indicator # define

Bookstore_h is placed after # ifndef, so that when the header file content is processed for the first time, bookstore_h will be defined. This prevents the value of the # ifndef indicator from being true in the program text file. This policy works well as long as there are no two header files that must be included to check a Preprocessor constant with the same name. # Ifdef indicators are often used to determine whether a Preprocessor constant has been defined to include program code with conditions.


In the include statement containing the header file, what is the difference between double quotation marks and angle brackets?

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.